[PATCH] D133457: Add Clang driver flags equivalent to cl's /MD, /MT, /MDd, /MTd.

2022-10-03 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

@akhuang I noticed that 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/MSVC.cpp#L199-L200
 has got an explicit check for `Args.hasArg(options::OPT__SLASH_MD, 
options::OPT__SLASH_MDd)` - I think that this would need to be amended to 
handle these cases too - or is that inferred from here somehow?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133457

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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-03 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Thanks for working on this! A few nits  inline




Comment at: clang/include/clang/Basic/LangOptions.h:369
+  enum class StrictFlexArraysLevelKind {
+/// Any trailing array memeber is a FAM.
+Default = 0,

typo: member



Comment at: clang/include/clang/Basic/LangOptions.h:373
+OneZeroOrIncomplete = 1,
+/// Any trailing array member of undefined or 0 is a FAM.
+ZeroOrIncomplete = 2,

+ size



Comment at: clang/include/clang/Basic/LangOptions.h:375
+ZeroOrIncomplete = 2,
+/// Any trailing array member of undefined or 0 is a FAM.
+Incomplete = 3,

I think you meant `Any trailing array member of undefined size is a FAM`



Comment at: clang/include/clang/Driver/Options.td:1155
+  NormalizedValuesScope<"LangOptions::StrictFlexArraysLevelKind">,
+  NormalizedValues<["Default", "OneZeroOrIncomplete", "ZeroOrIncomplete", 
"Incomplete"]>,
   HelpText<"Enable optimizations based on the strict definition of flexible 
arrays">,

Note that this depends on https://reviews.llvm.org/D134902 to have the 
"Incomplete" support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

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


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

2022-10-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 464889.
jansvoboda11 added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Actually add the MSVC flag after confirming the failure in CI.

  tools\clang\include\clang/Driver/Options.inc(7003): warning C4003: not enough 
arguments for function-like macro invocation 'GENERATE_OPTION_WITH_MARSHALLING'
  tools\clang\include\clang/Driver/Options.inc(7002): error C2059: syntax 
error: ')'
  tools\clang\include\clang/Driver/Options.inc(7003): error C2143: syntax 
error: missing ';' before '{'
  ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135128

Files:
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/cmake/modules/HandleLLVMOptions.cmake

Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -481,6 +481,8 @@
 
   append("/Zc:inline" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 
+  append("/Zc:preprocessor" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+
   # Some projects use the __cplusplus preprocessor macro to check support for
   # a particular version of the C++ standard. When this option is not specified
   # explicitly, macro's value is "199711L" that implies C++98 Standard.
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -423,7 +423,7 @@
   return ((KeyPath & Value) == Value) ? static_cast(Value) : T();
 }
 
-#define PARSE_OPTION_WITH_MARSHALLING( \
+#define PARSE_OPTION_WITH_MARSHALLING_IMPL(\
 ARGS, DIAGS, ID, FLAGS, PARAM, SHOULD_PARSE, KEYPATH, DEFAULT_VALUE,   \
 IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, MERGER, TABLE_INDEX) \
   if ((FLAGS)::CC1Option) {\
@@ -436,9 +436,18 @@
 MERGER(KEYPATH, static_cast(*MaybeValue));  \
   }
 
+#define PARSE_OPTION_WITH_MARSHALLING( \
+ARGS, DIAGS, PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS,  \
+PARAM, HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, \
+KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER,  \
+DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)  \
+  PARSE_OPTION_WITH_MARSHALLING_IMPL(  \
+  ARGS, DIAGS, ID, FLAGS, PARAM, SHOULD_PARSE, KEYPATH, DEFAULT_VALUE, \
+  IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, MERGER, TABLE_INDEX)
+
 // Capture the extracted value as a lambda argument to avoid potential issues
 // with lifetime extension of the reference.
-#define GENERATE_OPTION_WITH_MARSHALLING(  \
+#define GENERATE_OPTION_WITH_MARSHALLING_IMPL( \
 ARGS, STRING_ALLOCATOR, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH,   \
 DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR,  \
 TABLE_INDEX)   \
@@ -453,6 +462,16 @@
 }(EXTRACTOR(KEYPATH)); \
   }
 
+#define GENERATE_OPTION_WITH_MARSHALLING(  \
+ARGS, STRING_ALLOCATOR, PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, \
+ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES, SPELLING,  \
+SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK,  \
+IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)   \
+  GENERATE_OPTION_WITH_MARSHALLING_IMPL(   \
+  ARGS, STRING_ALLOCATOR, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH, \
+  DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR,\
+  TABLE_INDEX)
+
 static StringRef GetInputKindName(InputKind IK);
 
 static bool FixupInvocation(CompilerInvocation ,
@@ -809,14 +828,8 @@
  CompilerInvocation::StringAllocator SA) {
   const AnalyzerOptions *AnalyzerOpts = 
 
-#define ANALYZER_OPTION_WITH_MARSHALLING(  \
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   \
-DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
-MERGER, EXTRACTOR, TABLE_INDEX)\
-  GENERATE_OPTION_WITH_MARSHALLING(\
-  Args, SA, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,\
-  

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

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

Since we now only support Visual Studio 2019 16.7 and newer, we're able to use 
the /Zc:preprocessor flag that turns on the standards-conforming preprocessor 
that (among other things) correctly expands `__VA_ARGS__`. This enables us to 
get rid of some repetitive boilerplate in Clang's command-line parser.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135128

Files:
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -423,7 +423,7 @@
   return ((KeyPath & Value) == Value) ? static_cast(Value) : T();
 }
 
-#define PARSE_OPTION_WITH_MARSHALLING( \
+#define PARSE_OPTION_WITH_MARSHALLING_IMPL(\
 ARGS, DIAGS, ID, FLAGS, PARAM, SHOULD_PARSE, KEYPATH, DEFAULT_VALUE,   \
 IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, MERGER, TABLE_INDEX) \
   if ((FLAGS)::CC1Option) {\
@@ -436,9 +436,18 @@
 MERGER(KEYPATH, static_cast(*MaybeValue));  \
   }
 
+#define PARSE_OPTION_WITH_MARSHALLING( \
+ARGS, DIAGS, PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS,  \
+PARAM, HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, \
+KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER,  \
+DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)  \
+  PARSE_OPTION_WITH_MARSHALLING_IMPL(  \
+  ARGS, DIAGS, ID, FLAGS, PARAM, SHOULD_PARSE, KEYPATH, DEFAULT_VALUE, \
+  IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, MERGER, TABLE_INDEX)
+
 // Capture the extracted value as a lambda argument to avoid potential issues
 // with lifetime extension of the reference.
-#define GENERATE_OPTION_WITH_MARSHALLING(  \
+#define GENERATE_OPTION_WITH_MARSHALLING_IMPL( \
 ARGS, STRING_ALLOCATOR, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH,   \
 DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR,  \
 TABLE_INDEX)   \
@@ -453,6 +462,16 @@
 }(EXTRACTOR(KEYPATH)); \
   }
 
+#define GENERATE_OPTION_WITH_MARSHALLING(  \
+ARGS, STRING_ALLOCATOR, PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, \
+ALIASARGS, FLAGS, PARAM, HELPTEXT, METAVAR, VALUES, SPELLING,  \
+SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, IMPLIED_CHECK,  \
+IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, TABLE_INDEX)   \
+  GENERATE_OPTION_WITH_MARSHALLING_IMPL(   \
+  ARGS, STRING_ALLOCATOR, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH, \
+  DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR,\
+  TABLE_INDEX)
+
 static StringRef GetInputKindName(InputKind IK);
 
 static bool FixupInvocation(CompilerInvocation ,
@@ -809,14 +828,8 @@
  CompilerInvocation::StringAllocator SA) {
   const AnalyzerOptions *AnalyzerOpts = 
 
-#define ANALYZER_OPTION_WITH_MARSHALLING(  \
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   \
-DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
-MERGER, EXTRACTOR, TABLE_INDEX)\
-  GENERATE_OPTION_WITH_MARSHALLING(\
-  Args, SA, KIND, FLAGS, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE,\
-  IMPLIED_CHECK, IMPLIED_VALUE, DENORMALIZER, EXTRACTOR, TABLE_INDEX)
+#define ANALYZER_OPTION_WITH_MARSHALLING(...)  \
+  GENERATE_OPTION_WITH_MARSHALLING(Args, SA, __VA_ARGS__)
 #include "clang/Driver/Options.inc"
 #undef ANALYZER_OPTION_WITH_MARSHALLING
 
@@ -896,14 +909,8 @@
 
   AnalyzerOptions *AnalyzerOpts = 
 
-#define ANALYZER_OPTION_WITH_MARSHALLING(  \
-PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,\
-HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH,   \
-DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
-MERGER, EXTRACTOR, TABLE_INDEX)

[PATCH] D134507: [Clang] add missing ClangABICompat check

2022-10-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I left a comment on the old review thread; probably best to center the 
conversation there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134507

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-10-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Pinging this thread because it has more reviewers who probably have opinions 
about this.

https://reviews.llvm.org/D134507 is a patch that adds `-fclang-abi-compat` 
support around the breaking change here, which basically means that targets 
using old `-fclang-abi-compat` settings never get this change.  I've argued on 
that patch that that isn't the right way of resolving this issue.  Basically, 
the DR here is changing the language behavior in a way that you can imagine 
having ABI impact, but it's not primarily an ABI change, it's a language 
semantics change.  The ABI impact is purely that we potentially select a 
different overload in some cases, which can have downstream ODR impact.  I 
think the appropriate way to handle language semantics changes like this which 
potentially have compatibility impact is to condition them on language version. 
 Changing the target language standard is already broadly understood to have 
source/semantic compatibility impact, which is why we allow different target 
language standards to be specified in the first place.  This also makes it 
straightforward to document this potential break as a consequence of moving to 
`-std=c++23`, and it removes a potential rather bizarre portability issue where 
platforms that embrace stable ABIs are permanently stuck with a language 
dialect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D135011: Add builtin_elementwise_sin and builtin_elementwise_cos

2022-10-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Ah, I'd forgotten we had a bunch of elementwise builtins already.  I wouldn't 
be surprised if I asked for that in that patch, actually, especially because 
the existing ones include some functions like `max` and `min` where you could 
easily imagine them being cross-lane.  Nevermind.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen marked an inline comment as done.
ychen added a comment.

@mizvekov Thanks for the review!




Comment at: clang/lib/AST/ASTContext.cpp:5768-5769
   if (!IsCanon) {
 if (DeducedType.isNull()) {
-  SmallVector CanonArgs;
-  bool AnyNonCanonArgs =
-  ::getCanonicalTemplateArguments(*this, TypeConstraintArgs, 
CanonArgs);
-  if (AnyNonCanonArgs) {
+  if (TypeConstraintConcept) {
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,

mizvekov wrote:
> Last minor nit, but I think this looks more readable if you invert the isNull 
> check and do the `TypeConstraintConcept` on the else of that, less nesting.
Yep. That's better.



Comment at: clang/lib/AST/ASTContext.cpp:6335-6338
+   TX->hasPlaceholderTypeConstraint() ==
+   TY->hasPlaceholderTypeConstraint() &&
+   isSameConstraintExpr(TX->getPlaceholderTypeConstraint(),
+TY->getPlaceholderTypeConstraint());

mizvekov wrote:
> `isSameConstraintExpr` already handles that.
Ack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 464865.
ychen marked an inline comment as done.
ychen added a comment.

- Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Index: clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
===
--- clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
+++ clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
@@ -82,18 +82,12 @@
   template  class A {};
 
   template  C auto e(A) { return 0; }
-
-  // FIXME: The error here does not make sense.
   template auto e<>(A<>);
-  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
-  // expected-note@-5  {{candidate template ignored: failed template argument deduction}}
-
-  // FIXME: Should be able to instantiate this with no errors.
-  template C auto e(A);
-  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
-  // expected-note@-10 {{candidate template ignored: could not match 'C auto' against 'C auto'}}
-  
-  template C<> auto e<>(A<>);
+  template auto e(A);
+
+  template  C auto d(A) { return 0; }
+  template C<> auto d<>(A<>);
+  template C auto d(A);
 
   template  A c(Ts...);
   int f = e(c(1, 2));
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -7943,12 +7943,26 @@
  : Kind),
 TemplateArgLoc))
   return false;
-  } else if (Kind != Sema::TPL_TemplateTemplateArgumentMatch) {
+  }
+
+  if (Kind != Sema::TPL_TemplateTemplateArgumentMatch &&
+  !isa(Old)) {
 const Expr *NewC = nullptr, *OldC = nullptr;
-if (const auto *TC = cast(New)->getTypeConstraint())
-  NewC = TC->getImmediatelyDeclaredConstraint();
-if (const auto *TC = cast(Old)->getTypeConstraint())
-  OldC = TC->getImmediatelyDeclaredConstraint();
+
+if (isa(New)) {
+  if (const auto *TC = cast(New)->getTypeConstraint())
+NewC = TC->getImmediatelyDeclaredConstraint();
+  if (const auto *TC = cast(Old)->getTypeConstraint())
+OldC = TC->getImmediatelyDeclaredConstraint();
+} else if (isa(New)) {
+  if (const Expr *E = cast(New)
+  ->getPlaceholderTypeConstraint())
+NewC = E;
+  if (const Expr *E = cast(Old)
+  ->getPlaceholderTypeConstraint())
+OldC = E;
+} else
+  llvm_unreachable("unexpected template parameter type");
 
 auto Diagnose = [&] {
   S.Diag(NewC ? NewC->getBeginLoc() : New->getBeginLoc(),
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8661,10 +8661,11 @@
   // C++2a [class.spaceship]p2 [P2002R0]:
   //   Let R be the declared return type [...]. If R is auto, [...]. Otherwise,
   //   R shall not contain a placeholder type.
-  if (DCK == DefaultedComparisonKind::ThreeWay &&
-  FD->getDeclaredReturnType()->getContainedDeducedType() &&
-  !Context.hasSameType(FD->getDeclaredReturnType(),
-   Context.getAutoDeductType())) {
+  if (QualType RT = FD->getDeclaredReturnType();
+  DCK == DefaultedComparisonKind::ThreeWay &&
+  RT->getContainedDeducedType() &&
+  (!Context.hasSameType(RT, Context.getAutoDeductType()) ||
+   RT->getContainedAutoType()->isConstrained())) {
 Diag(FD->getLocation(),
  diag::err_defaulted_comparison_deduced_return_type_not_auto)
 << (int)DCK << FD->getDeclaredReturnType() << Context.AutoDeductTy
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -529,6 +529,9 @@
   ID.AddInteger(0);
   ID.AddBoolean(NTTP->isParameterPack());
   NTTP->getType().getCanonicalType().Profile(ID);
+  ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
+  if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
+E->Profile(ID, C, /*Canonical=*/true);
   continue;
 }
 if (const auto *TTP = dyn_cast(D)) {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -696,7 +696,11 @@
 if (const auto *NTTP = dyn_cast(*P)) {
   ID.AddInteger(1);
   ID.AddBoolean(NTTP->isParameterPack());
+  const Expr *TC = NTTP->getPlaceholderTypeConstraint();
+  ID.AddBoolean(TC != nullptr);
   

[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov accepted this revision.
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5768-5769
   if (!IsCanon) {
 if (DeducedType.isNull()) {
-  SmallVector CanonArgs;
-  bool AnyNonCanonArgs =
-  ::getCanonicalTemplateArguments(*this, TypeConstraintArgs, 
CanonArgs);
-  if (AnyNonCanonArgs) {
+  if (TypeConstraintConcept) {
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,

Last minor nit, but I think this looks more readable if you invert the isNull 
check and do the `TypeConstraintConcept` on the else of that, less nesting.



Comment at: clang/lib/AST/ASTContext.cpp:6335-6338
+   TX->hasPlaceholderTypeConstraint() ==
+   TY->hasPlaceholderTypeConstraint() &&
+   isSameConstraintExpr(TX->getPlaceholderTypeConstraint(),
+TY->getPlaceholderTypeConstraint());

`isSameConstraintExpr` already handles that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5745-5746
+  if (TypeConstraintConcept) {
+Canon = getAutoTypeInternal(QualType(), Keyword, false, IsPack, 
nullptr,
+{}, true);
 // Find the insert position again.

mizvekov wrote:
> ychen wrote:
> > ychen wrote:
> > > ychen wrote:
> > > > mizvekov wrote:
> > > > > Also adds back the `isDependent` flag. Any reason to have removed it?
> > > > I was thinking the replacement type is null, so there is no need to 
> > > > depend on instantiation?
> > > > I was thinking the replacement type is null, so there is no need to 
> > > > depend on instantiation?
> > > 
> > > 
> > Sorry I was not precise. I meant the constrained non-canonical AutoType 
> > would always be used for template instantiation. But I think it could 
> > happen that the user may query dependencies of the canonical AutoType of a 
> > constrained AutoType, maybe it just doesn't show up in the codebase yet. 
> > I'll put it back.
> FYI my memory is fuzzy right now, but we do have the distinction between 
> undeduced but non-dependent, and undeduced but dependent. It's suspicious 
> that no tests fail though. It could be either it doesn't matter for the 
> canonical type, or that the test would be a bit convoluted.
Yeah, I'm not confident to remove it right now. Already put it back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-03 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 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/D135118/new/

https://reviews.llvm.org/D135118

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5745-5746
+  if (TypeConstraintConcept) {
+Canon = getAutoTypeInternal(QualType(), Keyword, false, IsPack, 
nullptr,
+{}, true);
 // Find the insert position again.

ychen wrote:
> ychen wrote:
> > ychen wrote:
> > > mizvekov wrote:
> > > > Also adds back the `isDependent` flag. Any reason to have removed it?
> > > I was thinking the replacement type is null, so there is no need to 
> > > depend on instantiation?
> > > I was thinking the replacement type is null, so there is no need to 
> > > depend on instantiation?
> > 
> > 
> Sorry I was not precise. I meant the constrained non-canonical AutoType would 
> always be used for template instantiation. But I think it could happen that 
> the user may query dependencies of the canonical AutoType of a constrained 
> AutoType, maybe it just doesn't show up in the codebase yet. I'll put it back.
FYI my memory is fuzzy right now, but we do have the distinction between 
undeduced but non-dependent, and undeduced but dependent. It's suspicious that 
no tests fail though. It could be either it doesn't matter for the canonical 
type, or that the test would be a bit convoluted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 464861.
ychen added a comment.

- add back `IsDependent` parameter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Index: clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
===
--- clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
+++ clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
@@ -82,18 +82,12 @@
   template  class A {};
 
   template  C auto e(A) { return 0; }
-
-  // FIXME: The error here does not make sense.
   template auto e<>(A<>);
-  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
-  // expected-note@-5  {{candidate template ignored: failed template argument deduction}}
-
-  // FIXME: Should be able to instantiate this with no errors.
-  template C auto e(A);
-  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
-  // expected-note@-10 {{candidate template ignored: could not match 'C auto' against 'C auto'}}
-  
-  template C<> auto e<>(A<>);
+  template auto e(A);
+
+  template  C auto d(A) { return 0; }
+  template C<> auto d<>(A<>);
+  template C auto d(A);
 
   template  A c(Ts...);
   int f = e(c(1, 2));
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -7943,12 +7943,26 @@
  : Kind),
 TemplateArgLoc))
   return false;
-  } else if (Kind != Sema::TPL_TemplateTemplateArgumentMatch) {
+  }
+
+  if (Kind != Sema::TPL_TemplateTemplateArgumentMatch &&
+  !isa(Old)) {
 const Expr *NewC = nullptr, *OldC = nullptr;
-if (const auto *TC = cast(New)->getTypeConstraint())
-  NewC = TC->getImmediatelyDeclaredConstraint();
-if (const auto *TC = cast(Old)->getTypeConstraint())
-  OldC = TC->getImmediatelyDeclaredConstraint();
+
+if (isa(New)) {
+  if (const auto *TC = cast(New)->getTypeConstraint())
+NewC = TC->getImmediatelyDeclaredConstraint();
+  if (const auto *TC = cast(Old)->getTypeConstraint())
+OldC = TC->getImmediatelyDeclaredConstraint();
+} else if (isa(New)) {
+  if (const Expr *E = cast(New)
+  ->getPlaceholderTypeConstraint())
+NewC = E;
+  if (const Expr *E = cast(Old)
+  ->getPlaceholderTypeConstraint())
+OldC = E;
+} else
+  llvm_unreachable("unexpected template parameter type");
 
 auto Diagnose = [&] {
   S.Diag(NewC ? NewC->getBeginLoc() : New->getBeginLoc(),
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8661,10 +8661,11 @@
   // C++2a [class.spaceship]p2 [P2002R0]:
   //   Let R be the declared return type [...]. If R is auto, [...]. Otherwise,
   //   R shall not contain a placeholder type.
-  if (DCK == DefaultedComparisonKind::ThreeWay &&
-  FD->getDeclaredReturnType()->getContainedDeducedType() &&
-  !Context.hasSameType(FD->getDeclaredReturnType(),
-   Context.getAutoDeductType())) {
+  if (QualType RT = FD->getDeclaredReturnType();
+  DCK == DefaultedComparisonKind::ThreeWay &&
+  RT->getContainedDeducedType() &&
+  (!Context.hasSameType(RT, Context.getAutoDeductType()) ||
+   RT->getContainedAutoType()->isConstrained())) {
 Diag(FD->getLocation(),
  diag::err_defaulted_comparison_deduced_return_type_not_auto)
 << (int)DCK << FD->getDeclaredReturnType() << Context.AutoDeductTy
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -529,6 +529,9 @@
   ID.AddInteger(0);
   ID.AddBoolean(NTTP->isParameterPack());
   NTTP->getType().getCanonicalType().Profile(ID);
+  ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
+  if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
+E->Profile(ID, C, /*Canonical=*/true);
   continue;
 }
 if (const auto *TTP = dyn_cast(D)) {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -696,7 +696,11 @@
 if (const auto *NTTP = dyn_cast(*P)) {
   ID.AddInteger(1);
   ID.AddBoolean(NTTP->isParameterPack());
+  const Expr *TC = NTTP->getPlaceholderTypeConstraint();
+  ID.AddBoolean(TC != nullptr);
   

[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5745-5746
+  if (TypeConstraintConcept) {
+Canon = getAutoTypeInternal(QualType(), Keyword, false, IsPack, 
nullptr,
+{}, true);
 // Find the insert position again.

ychen wrote:
> mizvekov wrote:
> > Also adds back the `isDependent` flag. Any reason to have removed it?
> I was thinking the replacement type is null, so there is no need to depend on 
> instantiation?
> I was thinking the replacement type is null, so there is no need to depend on 
> instantiation?





Comment at: clang/lib/AST/ASTContext.cpp:5745-5746
+  if (TypeConstraintConcept) {
+Canon = getAutoTypeInternal(QualType(), Keyword, false, IsPack, 
nullptr,
+{}, true);
 // Find the insert position again.

ychen wrote:
> ychen wrote:
> > mizvekov wrote:
> > > Also adds back the `isDependent` flag. Any reason to have removed it?
> > I was thinking the replacement type is null, so there is no need to depend 
> > on instantiation?
> > I was thinking the replacement type is null, so there is no need to depend 
> > on instantiation?
> 
> 
Sorry I was not precise. I meant the constrained non-canonical AutoType would 
always be used for template instantiation. But I think it could happen that the 
user may query dependencies of the canonical AutoType of a constrained 
AutoType, maybe it just doesn't show up in the codebase yet. I'll put it back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8664-8668
+  if (QualType RT = FD->getDeclaredReturnType();
+  DCK == DefaultedComparisonKind::ThreeWay &&
+  RT->getContainedDeducedType() &&
+  (!Context.hasSameType(RT, Context.getAutoDeductType()) ||
+   RT->getContainedAutoType()->isConstrained())) {

ychen wrote:
> mizvekov wrote:
> > I think this might crash if the three-way comparison is defaulted with a 
> > deduced template specialization.
> > 
> > Something like:
> > ```
> > template  struct A {};
> > 
> > struct P {
> >   friend A operator<=>(const P&, const P&) = default;
> > };
> > ```
> > 
> > The problem is that `RT->getContainedDeducedType()` will return non-null, 
> > because DTSTs are also deduced types, but `RT->getContainedAutoType()` will 
> > return null, because DTSTs are not AutoTypes.
> > I think this might crash if the three-way comparison is defaulted with a 
> > deduced template specialization.
> > The problem is that `RT->getContainedDeducedType()` will return non-null, 
> > because DTSTs are also deduced types, but `RT->getContainedAutoType()` will 
> > return null, because DTSTs are not AutoTypes.
> 
> `RT->getContainedAutoType()` will be called only when `RT` is `AutoType`?
Oh right, I see it now, there is a lot going on in that condition :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 464858.
ychen added a comment.

- remove dead code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Index: clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
===
--- clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
+++ clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
@@ -82,18 +82,12 @@
   template  class A {};
 
   template  C auto e(A) { return 0; }
-
-  // FIXME: The error here does not make sense.
   template auto e<>(A<>);
-  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
-  // expected-note@-5  {{candidate template ignored: failed template argument deduction}}
-
-  // FIXME: Should be able to instantiate this with no errors.
-  template C auto e(A);
-  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a function template}}
-  // expected-note@-10 {{candidate template ignored: could not match 'C auto' against 'C auto'}}
-  
-  template C<> auto e<>(A<>);
+  template auto e(A);
+
+  template  C auto d(A) { return 0; }
+  template C<> auto d<>(A<>);
+  template C auto d(A);
 
   template  A c(Ts...);
   int f = e(c(1, 2));
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -7943,12 +7943,26 @@
  : Kind),
 TemplateArgLoc))
   return false;
-  } else if (Kind != Sema::TPL_TemplateTemplateArgumentMatch) {
+  }
+
+  if (Kind != Sema::TPL_TemplateTemplateArgumentMatch &&
+  !isa(Old)) {
 const Expr *NewC = nullptr, *OldC = nullptr;
-if (const auto *TC = cast(New)->getTypeConstraint())
-  NewC = TC->getImmediatelyDeclaredConstraint();
-if (const auto *TC = cast(Old)->getTypeConstraint())
-  OldC = TC->getImmediatelyDeclaredConstraint();
+
+if (isa(New)) {
+  if (const auto *TC = cast(New)->getTypeConstraint())
+NewC = TC->getImmediatelyDeclaredConstraint();
+  if (const auto *TC = cast(Old)->getTypeConstraint())
+OldC = TC->getImmediatelyDeclaredConstraint();
+} else if (isa(New)) {
+  if (const Expr *E = cast(New)
+  ->getPlaceholderTypeConstraint())
+NewC = E;
+  if (const Expr *E = cast(Old)
+  ->getPlaceholderTypeConstraint())
+OldC = E;
+} else
+  llvm_unreachable("unexpected template parameter type");
 
 auto Diagnose = [&] {
   S.Diag(NewC ? NewC->getBeginLoc() : New->getBeginLoc(),
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -8661,10 +8661,11 @@
   // C++2a [class.spaceship]p2 [P2002R0]:
   //   Let R be the declared return type [...]. If R is auto, [...]. Otherwise,
   //   R shall not contain a placeholder type.
-  if (DCK == DefaultedComparisonKind::ThreeWay &&
-  FD->getDeclaredReturnType()->getContainedDeducedType() &&
-  !Context.hasSameType(FD->getDeclaredReturnType(),
-   Context.getAutoDeductType())) {
+  if (QualType RT = FD->getDeclaredReturnType();
+  DCK == DefaultedComparisonKind::ThreeWay &&
+  RT->getContainedDeducedType() &&
+  (!Context.hasSameType(RT, Context.getAutoDeductType()) ||
+   RT->getContainedAutoType()->isConstrained())) {
 Diag(FD->getLocation(),
  diag::err_defaulted_comparison_deduced_return_type_not_auto)
 << (int)DCK << FD->getDeclaredReturnType() << Context.AutoDeductTy
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -529,6 +529,9 @@
   ID.AddInteger(0);
   ID.AddBoolean(NTTP->isParameterPack());
   NTTP->getType().getCanonicalType().Profile(ID);
+  ID.AddBoolean(NTTP->hasPlaceholderTypeConstraint());
+  if (const Expr *E = NTTP->getPlaceholderTypeConstraint())
+E->Profile(ID, C, /*Canonical=*/true);
   continue;
 }
 if (const auto *TTP = dyn_cast(D)) {
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -696,7 +696,11 @@
 if (const auto *NTTP = dyn_cast(*P)) {
   ID.AddInteger(1);
   ID.AddBoolean(NTTP->isParameterPack());
+  const Expr *TC = NTTP->getPlaceholderTypeConstraint();
+  ID.AddBoolean(TC != nullptr);
   

[PATCH] D135099: [C2x] Implement support for nullptr and nullptr_t

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



Comment at: clang/lib/Sema/SemaExpr.cpp:8730
+  //   result also has that type.
+  if (LHSTy->isNullPtrType() && Context.hasSameType(LHSTy, RHSTy))
+return ResTy;

erichkeane wrote:
> what does this do with the GNU ternary-thing?  
Does this cover if one is a pointer with a null pointer value?



Comment at: clang/lib/Sema/SemaExpr.cpp:12587
 
-// Comparison of Objective-C pointers and block pointers against nullptr_t.
-// These aren't covered by the composite pointer type rules.
-if (!IsOrdered && RHSType->isNullPtrType() &&
-(LHSType->isObjCObjectPointerType() || LHSType->isBlockPointerType())) 
{
+  // C++ [expr.eq]p4:
+  //   Two operands of type std::nullptr_t or one operand of type

This was in the `if (getLangOpts().CPlusPlus)` block previously, did you mean 
to move it out?



Comment at: clang/lib/Sema/SemaExpr.cpp:12620
+
+  // Comparison of Objective-C pointers and block pointers against nullptr_t.
+  // These aren't covered by the composite pointer type rules.

This was in the `if (getLangOpts().CPlusPlus)` block previously, did you mean 
to move it out?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135099

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-03 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi created this revision.
Herald added a subscriber: mgrang.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In the context of caching clang invocations it is important to emit diagnostics 
in deterministic order;
the same clang invocation should result in the same diagnostic output.

rdar://100336989


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135118

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Scope.h
  clang/test/Sema/deterministic-diagnostics-order.m

Index: clang/test/Sema/deterministic-diagnostics-order.m
===
--- /dev/null
+++ clang/test/Sema/deterministic-diagnostics-order.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wobjc-property-implementation -Watomic-property-with-user-defined-accessor -Wunused 2> %t.err
+// RUN: FileCheck -input-file=%t.err %s
+
+@interface I
+@end
+
+@interface I(cat)
+@property id prop1;
+@property id prop2;
+@property id prop3;
+@end
+
+@implementation I(cat)
+@end
+
+// CHECK: warning: property 'prop1' requires method
+// CHECK: warning: property 'prop2' requires method
+// CHECK: warning: property 'prop3' requires method
+
+@interface I2
+@property int prop1;
+@property int prop2;
+@property int prop3;
+@end
+
+@implementation I2
+@synthesize prop1, prop2, prop3;
+-(int) prop1 { return 0; }
+-(int) prop2 { return 0; }
+-(int) prop3 { return 0; }
+@end
+
+// CHECK: warning: writable atomic property 'prop1'
+// CHECK: warning: writable atomic property 'prop2'
+// CHECK: warning: writable atomic property 'prop3'
+
+void test_unused() {
+  // Add enough variables to exceed the small storage of Scope::DeclSetTy.
+  int v1;
+  int v2;
+  int v3;
+  int v4;
+  int v5;
+  int v6;
+  int v7;
+  int v8;
+  int v9;
+  int v10;
+  int v11;
+  int v12;
+  int v13;
+  int v14;
+  int v15;
+  int v16;
+  int v17;
+  int v18;
+  int v19;
+  int v20;
+  int v21;
+  int v22;
+  int v23;
+  int v24;
+  int v25;
+  int v26;
+  int v27;
+  int v28;
+  int v29;
+  int v30;
+  int v31;
+  int v32;
+  int v33;
+  int v34;
+  int v35;
+  int v36;
+  int v37;
+  int v38;
+}
+
+// CHECK: warning: unused variable 'v1'
+// CHECK: warning: unused variable 'v2'
+// CHECK: warning: unused variable 'v3'
+// CHECK: warning: unused variable 'v4'
+// CHECK: warning: unused variable 'v5'
+// CHECK: warning: unused variable 'v6'
+// CHECK: warning: unused variable 'v7'
+// CHECK: warning: unused variable 'v8'
+// CHECK: warning: unused variable 'v9'
+// CHECK: warning: unused variable 'v10'
+// CHECK: warning: unused variable 'v11'
+// CHECK: warning: unused variable 'v12'
+// CHECK: warning: unused variable 'v13'
+// CHECK: warning: unused variable 'v14'
+// CHECK: warning: unused variable 'v15'
+// CHECK: warning: unused variable 'v16'
+// CHECK: warning: unused variable 'v17'
+// CHECK: warning: unused variable 'v18'
+// CHECK: warning: unused variable 'v19'
+// CHECK: warning: unused variable 'v20'
+// CHECK: warning: unused variable 'v21'
+// CHECK: warning: unused variable 'v22'
+// CHECK: warning: unused variable 'v23'
+// CHECK: warning: unused variable 'v24'
+// CHECK: warning: unused variable 'v25'
+// CHECK: warning: unused variable 'v26'
+// CHECK: warning: unused variable 'v27'
+// CHECK: warning: unused variable 'v28'
+// CHECK: warning: unused variable 'v29'
+// CHECK: warning: unused variable 'v30'
+// CHECK: warning: unused variable 'v31'
+// CHECK: warning: unused variable 'v32'
+// CHECK: warning: unused variable 'v33'
+// CHECK: warning: unused variable 'v34'
+// CHECK: warning: unused variable 'v35'
+// CHECK: warning: unused variable 'v36'
+// CHECK: warning: unused variable 'v37'
+// CHECK: warning: unused variable 'v38'
Index: clang/include/clang/Sema/Scope.h
===
--- clang/include/clang/Sema/Scope.h
+++ clang/include/clang/Sema/Scope.h
@@ -16,6 +16,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -196,7 +197,7 @@
   /// popped, these declarations are removed from the IdentifierTable's notion
   /// of current declaration.  It is up to the current Action implementation to
   /// implement these semantics.
-  using DeclSetTy = llvm::SmallPtrSet;
+  using DeclSetTy = llvm::SmallSetVector;
   DeclSetTy DeclsInScope;
 
   /// The DeclContext with which this scope is associated. For
@@ -321,9 +322,7 @@
 DeclsInScope.insert(D);
   }
 
-  void RemoveDecl(Decl *D) {
-DeclsInScope.erase(D);
-  }
+  void RemoveDecl(Decl *D) { DeclsInScope.remove(D); }
 
   void incrementMSManglingNumber() {
 if (Scope *MSLMP = getMSLastManglingParent()) {
@@ -351,7 +350,9 @@
 
   /// isDeclScope - Return true if 

[PATCH] D134820: [LTO][clang] Teaching Clang to Pass Plugin Options to the AIX Linker

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

LGTM




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:72
+CmdArgs.push_back(Args.MakeArgString(
+Twine(PluginOptPrefix) + Twine("-pass-remarks=") + A->getValue()));
 

Adding `Twine` to one operand of `+` suffices.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:76
+CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
+ Twine("-pass-remarks-missed=") +
+ A->getValue()));

Adding `Twine` to one operand of `+` suffices.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:495
+  const bool IsOSAIX = ToolChain.getTriple().isOSAIX();
+
   const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());

delete blank line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134820

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5736-5737
   llvm::FoldingSetNodeID ID;
   AutoType::Profile(ID, *this, DeducedType, Keyword, IsDependent,
 TypeConstraintConcept, TypeConstraintArgs);
   if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))

mizvekov wrote:
> FYI (not asking you to fix this on this patch) there is a pre-existing bug 
> here where we are not profiling the node on the `isPack` flag.
> FYI (not asking you to fix this on this patch) there is a pre-existing bug 
> here where we are not profiling the node on the `isPack` flag.

Thanks. Great to know.



Comment at: clang/lib/AST/ASTContext.cpp:5745-5746
+  if (TypeConstraintConcept) {
+Canon = getAutoTypeInternal(QualType(), Keyword, false, IsPack, 
nullptr,
+{}, true);
 // Find the insert position again.

mizvekov wrote:
> Also adds back the `isDependent` flag. Any reason to have removed it?
I was thinking the replacement type is null, so there is no need to depend on 
instantiation?



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8664-8668
+  if (QualType RT = FD->getDeclaredReturnType();
+  DCK == DefaultedComparisonKind::ThreeWay &&
+  RT->getContainedDeducedType() &&
+  (!Context.hasSameType(RT, Context.getAutoDeductType()) ||
+   RT->getContainedAutoType()->isConstrained())) {

mizvekov wrote:
> I think this might crash if the three-way comparison is defaulted with a 
> deduced template specialization.
> 
> Something like:
> ```
> template  struct A {};
> 
> struct P {
>   friend A operator<=>(const P&, const P&) = default;
> };
> ```
> 
> The problem is that `RT->getContainedDeducedType()` will return non-null, 
> because DTSTs are also deduced types, but `RT->getContainedAutoType()` will 
> return null, because DTSTs are not AutoTypes.
> I think this might crash if the three-way comparison is defaulted with a 
> deduced template specialization.
> The problem is that `RT->getContainedDeducedType()` will return non-null, 
> because DTSTs are also deduced types, but `RT->getContainedAutoType()` will 
> return null, because DTSTs are not AutoTypes.

`RT->getContainedAutoType()` will be called only when `RT` is `AutoType`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-10-03 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic marked an inline comment as done.
jpenix-quic added a comment.

In D130513#3827108 , @jeanPerier 
wrote:

> The lowering part looks good to me (I only have a minor comment inlined about 
> a header used in lowering).

Thank you @jeanPerier for looking over the lowering portion! Regarding moving 
the header (I'm replying to the comment here since the inline one now opens in 
a separate revision/window as the file is gone), I moved it to 
Lower/EnvironmentDefault.h as lowering is where I use it (as you mentioned). 
Please let me know if this needs further changes!

Just to confirm/as a final check, @awarzynski does the driver portion look good 
to you? Similarly, @klausler does the runtime portion look good to you? I 
believe I addressed the comments you both left previously, but I want to make 
sure that I addressed things appropriately. Thanks!


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

https://reviews.llvm.org/D130513

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


[PATCH] D135088: [Clang] make canonical AutoType constraints-free

2022-10-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/lib/AST/ASTContext.cpp:5730-5732
   if (TypeConstraintConcept)
 TypeConstraintConcept = TypeConstraintConcept->getCanonicalDecl();
 

Pre-existing problem: This was not good to begin with, since we would not 
capture the correct declaration used, but now you can just remove it, no 
further changes required.



Comment at: clang/lib/AST/ASTContext.cpp:5736-5737
   llvm::FoldingSetNodeID ID;
   AutoType::Profile(ID, *this, DeducedType, Keyword, IsDependent,
 TypeConstraintConcept, TypeConstraintArgs);
   if (AutoType *AT = AutoTypes.FindNodeOrInsertPos(ID, InsertPos))

FYI (not asking you to fix this on this patch) there is a pre-existing bug here 
where we are not profiling the node on the `isPack` flag.



Comment at: clang/lib/AST/ASTContext.cpp:5745-5746
+  if (TypeConstraintConcept) {
+Canon = getAutoTypeInternal(QualType(), Keyword, false, IsPack, 
nullptr,
+{}, true);
 // Find the insert position again.

Also adds back the `isDependent` flag. Any reason to have removed it?



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:8664-8668
+  if (QualType RT = FD->getDeclaredReturnType();
+  DCK == DefaultedComparisonKind::ThreeWay &&
+  RT->getContainedDeducedType() &&
+  (!Context.hasSameType(RT, Context.getAutoDeductType()) ||
+   RT->getContainedAutoType()->isConstrained())) {

I think this might crash if the three-way comparison is defaulted with a 
deduced template specialization.

Something like:
```
template  struct A {};

struct P {
  friend A operator<=>(const P&, const P&) = default;
};
```

The problem is that `RT->getContainedDeducedType()` will return non-null, 
because DTSTs are also deduced types, but `RT->getContainedAutoType()` will 
return null, because DTSTs are not AutoTypes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135088

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


[PATCH] D135011: Add sin and cos llvm builtins

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

In D135011#3831949 , @rjmccall wrote:

> The titled of this patch should be something like "Add 
> __builtin_elementwise_sin and __builtin_elementwise_cos".
>
> Can you explain why this uses a new builtin name instead of overloading the 
> existing builtins to work on vectors?  I can imagine reasons why, but I think 
> it needs to be explained.  I can't imagine `cos` and `sin` not being 
> element-wise operations on a vector.

It just adds additional builtins following the other vector-wise builtins.
As mentioned in 
https://lists.llvm.org/pipermail/cfe-dev/2021-September/068999.html, it is much 
easier to just use one builtin for all overloads instead of using different 
builtins for different overloads.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D133683: [c++] implements tentative DR1432 for partial ordering of function template

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1fb728e95c74: [c++] implements tentative DR1432 for partial 
ordering of function template (authored by ychen).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133683

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/drs/dr6xx.cpp
  clang/test/SemaCXX/pre-dr692.cpp

Index: clang/test/SemaCXX/pre-dr692.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/pre-dr692.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -std=c++11 -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking -fclang-abi-compat=15
+
+template  struct A1 {};
+template  struct A2 {};
+template  void e1(A1);  // expected-note {{candidate}}
+template  void e1(A1);  // expected-note {{candidate}}
+template  void e2(A2);  // expected-note {{candidate}}
+template  void e2(A2);  // expected-note {{candidate}}
+void h() {
+  A1 b1;
+  e1(b1); // expected-error{{call to 'e1' is ambiguous}}
+  A2 b2;
+  e2(b2); // expected-error{{call to 'e2' is ambiguous}}
+}
Index: clang/test/CXX/drs/dr6xx.cpp
===
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1083,13 +1083,23 @@
   // Also see dr1395.
 
   namespace temp_func_order_example2 {
-template  struct A {};
-template  void f(U, A *p = 0); // expected-note {{candidate}}
-template  int (U, A *p = 0); // expected-note {{candidate}}
+template  struct A1 {}; // expected-error 0-1{{C++11}}
+template  struct A2 {}; // expected-error 0-1{{C++11}}
+template  void e1(A1) = delete; // expected-error 0-2{{C++11}}
+template  void e1(A1);
+template  void e2(A2) = delete; // expected-error 0-2{{C++11}}
+template  void e2(A2);
+template  void f(U, A1 *p = 0) = delete; // expected-note {{candidate}} expected-error 0-1{{C++11}}
+template  int (U, A1 *p = 0); // expected-note {{candidate}}
 template  void g(T, T = T()); // expected-note {{candidate}}
 template  void g(T, U...); // expected-note {{candidate}} expected-error 0-1{{C++11}}
 void h() {
-  int  = f(42, (A *)0);
+  A1 a;
+  int  = f(42, );
+  A1 b1;
+  e1(b1);
+  A2 b2;
+  e2(b2);
   f(42); // expected-error {{ambiguous}}
   g(42); // expected-error {{ambiguous}}
 }
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5222,6 +5222,39 @@
   return FT1;
   }
 
+  // This a speculative fix for CWG1432 (Similar to the fix for CWG1395) that
+  // there is no wording or even resolution for this issue.
+  bool ClangABICompat15 =
+  Context.getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver15;
+  if (!ClangABICompat15) {
+for (int i = 0, e = std::min(NumParams1, NumParams2); i < e; ++i) {
+  QualType T1 = FD1->getParamDecl(i)->getType().getCanonicalType();
+  QualType T2 = FD2->getParamDecl(i)->getType().getCanonicalType();
+  auto *TST1 = dyn_cast(T1);
+  auto *TST2 = dyn_cast(T2);
+  if (!TST1 || !TST2)
+continue;
+  const TemplateArgument  = TST1->template_arguments().back();
+  if (TA1.getKind() == TemplateArgument::Pack) {
+assert(TST1->getNumArgs() == TST2->getNumArgs());
+const TemplateArgument  = TST2->template_arguments().back();
+assert(TA2.getKind() == TemplateArgument::Pack);
+unsigned PackSize1 = TA1.pack_size();
+unsigned PackSize2 = TA2.pack_size();
+bool IsPackExpansion1 =
+PackSize1 && TA1.pack_elements().back().isPackExpansion();
+bool IsPackExpansion2 =
+PackSize2 && TA2.pack_elements().back().isPackExpansion();
+if (PackSize1 != PackSize2 && IsPackExpansion1 != IsPackExpansion2) {
+  if (PackSize1 > PackSize2 && IsPackExpansion1)
+return FT2;
+  if (PackSize1 < PackSize2 && IsPackExpansion2)
+return FT1;
+}
+  }
+}
+  }
+
   return JudgeByConstraints();
 }
 
@@ -5457,30 +5490,29 @@
 return nullptr;
 
   if (Better1 && Better2) {
+// This a speculative fix for CWG1432 (Similar to the fix for CWG1395) that
+// there is no wording or even resolution for this issue.
 bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
 LangOptions::ClangABI::Ver15;
 if (!ClangABICompat15) {
-  // Consider this a fix for CWG1432. Similar to the fix for CWG1395.
-  auto *TST1 = T1->castAs();
-  auto *TST2 = T2->castAs();
-  if (TST1->getNumArgs()) {
-const TemplateArgument  = TST1->template_arguments().back();
-if (TA1.getKind() == 

[clang] 1fb728e - [c++] implements tentative DR1432 for partial ordering of function template

2022-10-03 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-10-03T16:30:27-07:00
New Revision: 1fb728e95c74bf72698c00094f18fa8d2eb42cda

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

LOG: [c++] implements tentative DR1432 for partial ordering of function template

D128745 handled DR1432 for the partial ordering of partial specializations, but
missed the handling for the partial ordering of function templates. This patch
implements the latter. While at it, also simplifies the previous implementation 
to
be more close to the wording without functional changes.

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

Reviewed By: erichkeane, #clang-language-wg, mizvekov

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

Added: 
clang/test/SemaCXX/pre-dr692.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/drs/dr6xx.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2320f4a7a4fa..d113d9b450b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -363,7 +363,9 @@ C2x Feature Support
 C++ Language Changes in Clang
 -
 - Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` 
option
-  to get the old partial ordering behavior regarding packs.
+  to get the old partial ordering behavior regarding packs. Note that the fix 
for
+  DR1432 is speculative that there is no wording or even resolution for this 
issue.
+  A speculative fix for DR1432 is needed because it fixes regressions caused 
by DR692.
 - Clang's default C++/ObjC++ standard is now ``gnu++17`` instead of 
``gnu++14``.
   This means Clang will by default accept code using features from C++17 and
   conforming GNU extensions. Projects incompatible with C++17 can add

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6ddbd9055870..e3301081da55 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5222,6 +5222,39 @@ FunctionTemplateDecl *Sema::getMoreSpecializedTemplate(
   return FT1;
   }
 
+  // This a speculative fix for CWG1432 (Similar to the fix for CWG1395) that
+  // there is no wording or even resolution for this issue.
+  bool ClangABICompat15 =
+  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver15;
+  if (!ClangABICompat15) {
+for (int i = 0, e = std::min(NumParams1, NumParams2); i < e; ++i) {
+  QualType T1 = FD1->getParamDecl(i)->getType().getCanonicalType();
+  QualType T2 = FD2->getParamDecl(i)->getType().getCanonicalType();
+  auto *TST1 = dyn_cast(T1);
+  auto *TST2 = dyn_cast(T2);
+  if (!TST1 || !TST2)
+continue;
+  const TemplateArgument  = TST1->template_arguments().back();
+  if (TA1.getKind() == TemplateArgument::Pack) {
+assert(TST1->getNumArgs() == TST2->getNumArgs());
+const TemplateArgument  = TST2->template_arguments().back();
+assert(TA2.getKind() == TemplateArgument::Pack);
+unsigned PackSize1 = TA1.pack_size();
+unsigned PackSize2 = TA2.pack_size();
+bool IsPackExpansion1 =
+PackSize1 && TA1.pack_elements().back().isPackExpansion();
+bool IsPackExpansion2 =
+PackSize2 && TA2.pack_elements().back().isPackExpansion();
+if (PackSize1 != PackSize2 && IsPackExpansion1 != IsPackExpansion2) {
+  if (PackSize1 > PackSize2 && IsPackExpansion1)
+return FT2;
+  if (PackSize1 < PackSize2 && IsPackExpansion2)
+return FT1;
+}
+  }
+}
+  }
+
   return JudgeByConstraints();
 }
 
@@ -5457,30 +5490,29 @@ getMoreSpecialized(Sema , QualType T1, QualType T2, 
TemplateLikeDecl *P1,
 return nullptr;
 
   if (Better1 && Better2) {
+// This a speculative fix for CWG1432 (Similar to the fix for CWG1395) that
+// there is no wording or even resolution for this issue.
 bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
 LangOptions::ClangABI::Ver15;
 if (!ClangABICompat15) {
-  // Consider this a fix for CWG1432. Similar to the fix for CWG1395.
-  auto *TST1 = T1->castAs();
-  auto *TST2 = T2->castAs();
-  if (TST1->getNumArgs()) {
-const TemplateArgument  = TST1->template_arguments().back();
-if (TA1.getKind() == TemplateArgument::Pack) {
-  assert(TST1->getNumArgs() == TST2->getNumArgs());
-  const TemplateArgument  = TST2->template_arguments().back();
-  assert(TA2.getKind() == TemplateArgument::Pack);
-  unsigned PackSize1 = TA1.pack_size();
-  unsigned PackSize2 = TA2.pack_size();
-  bool 

[PATCH] D135110: [NFC] [HLSL] Move common metadata to LLVMFrontend

2022-10-03 Thread Xiang Li via Phabricator via cfe-commits
python3kgae added inline comments.



Comment at: llvm/include/llvm/Frontend/HLSL/HLSLResource.h:35
+  GlobalVariable *getGlobalVariable();
+  StringRef getSourceType();
+  Constant *getID();

Could we save things like shape and component type instead of a StringRef which 
needs to be parsed later?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135110

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-10-03 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic updated this revision to Diff 464849.
jpenix-quic added a comment.

Add /*overwrite=*/ comment I missed previously, move 
Runtime/environment-defaults.h to Lower/EnvironmentDefault.h


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

https://reviews.llvm.org/D130513

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/examples/external-hello.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/Lower/Bridge.h
  flang/include/flang/Lower/EnvironmentDefault.h
  flang/include/flang/Optimizer/Builder/Runtime/EnvironmentDefaults.h
  flang/include/flang/Runtime/main.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Lower/Bridge.cpp
  flang/lib/Optimizer/Builder/CMakeLists.txt
  flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp
  flang/runtime/FortranMain/Fortran_main.c
  flang/runtime/environment-default-list.h
  flang/runtime/environment.cpp
  flang/runtime/environment.h
  flang/runtime/main.cpp
  flang/test/Driver/convert.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-mlir.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Lower/convert.f90
  flang/test/Lower/environment-defaults.f90
  flang/test/Runtime/no-cpp-dep.c
  flang/tools/bbc/bbc.cpp
  flang/unittests/Runtime/CommandTest.cpp
  flang/unittests/Runtime/Stop.cpp

Index: flang/unittests/Runtime/Stop.cpp
===
--- flang/unittests/Runtime/Stop.cpp
+++ flang/unittests/Runtime/Stop.cpp
@@ -26,7 +26,8 @@
 
 TEST(TestProgramEnd, StopTestNoStopMessage) {
   putenv(const_cast("NO_STOP_MESSAGE=1"));
-  Fortran::runtime::executionEnvironment.Configure(0, nullptr, nullptr);
+  Fortran::runtime::executionEnvironment.Configure(
+  0, nullptr, nullptr, nullptr);
   EXPECT_EXIT(
   RTNAME(StopStatement)(), testing::ExitedWithCode(EXIT_SUCCESS), "");
 }
@@ -52,7 +53,8 @@
 
 TEST(TestProgramEnd, NoStopMessageTest) {
   putenv(const_cast("NO_STOP_MESSAGE=1"));
-  Fortran::runtime::executionEnvironment.Configure(0, nullptr, nullptr);
+  Fortran::runtime::executionEnvironment.Configure(
+  0, nullptr, nullptr, nullptr);
   static const char *message{"bye bye"};
   EXPECT_EXIT(RTNAME(StopStatementText)(message, std::strlen(message),
   /*isErrorStop=*/false, /*quiet=*/false),
Index: flang/unittests/Runtime/CommandTest.cpp
===
--- flang/unittests/Runtime/CommandTest.cpp
+++ flang/unittests/Runtime/CommandTest.cpp
@@ -49,7 +49,7 @@
 class CommandFixture : public ::testing::Test {
 protected:
   CommandFixture(int argc, const char *argv[]) {
-RTNAME(ProgramStart)(argc, argv, {});
+RTNAME(ProgramStart)(argc, argv, {}, {});
   }
 
   std::string GetPaddedStr(const char *text, std::size_t len) const {
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -224,7 +224,7 @@
   auto burnside = Fortran::lower::LoweringBridge::create(
   ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(), "",
-  kindMap, loweringOptions);
+  kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
   std::error_code ec;
Index: flang/test/Runtime/no-cpp-dep.c
===
--- flang/test/Runtime/no-cpp-dep.c
+++ flang/test/Runtime/no-cpp-dep.c
@@ -16,18 +16,20 @@
 we're testing. We can't include any headers directly since they likely contain
 C++ code that would explode here.
 */
+struct EnvironmentDefaultList;
 struct Descriptor;
 
 double RTNAME(CpuTime)();
 
-void RTNAME(ProgramStart)(int, const char *[], const char *[]);
+void RTNAME(ProgramStart)(
+int, const char *[], const char *[], const struct EnvironmentDefaultList *);
 int32_t RTNAME(ArgumentCount)();
 int32_t RTNAME(GetCommandArgument)(int32_t, const struct Descriptor *,
 const struct Descriptor *, const struct Descriptor *);
 
 int main() {
   double x = RTNAME(CpuTime)();
-  RTNAME(ProgramStart)(0, 0, 0);
+  RTNAME(ProgramStart)(0, 0, 0, 0);
   int32_t c = RTNAME(ArgumentCount)();
   int32_t v = RTNAME(GetCommandArgument)(0, 0, 0, 0);
   return x + c + v;
Index: flang/test/Lower/environment-defaults.f90
===
--- /dev/null
+++ flang/test/Lower/environment-defaults.f90
@@ -0,0 +1,12 @@
+! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+program test
+  continue
+end
+
+! Test that a null pointer is generated for environment defaults if nothing is specified
+
+! CHECK: fir.global @_QQEnvironmentDefaults constant : !fir.ref, 

[PATCH] D134454: [Driver][Distro] Fix ArchLinux sysroot detection

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

- This patch should be abandoned. Inferring sysroot from gcc-toolchain is 
backward.
- The D644  (`Support Sourcery CodeBench MIPS 
toolchain`) `computeSysRoot` should not be used by new support.
- `--gcc-toolchain=` is discouraged.
- New cross compilation support should specify `--target=` with `--sysroot=` 
and possibly `--gcc-install-dir=`.
- If a distro wants to just use `--target=`, provide a configuration file.
- Gentoo folks are working on making 
https://github.com/llvm/llvm-project/issues/57570 less hacky (and eventually 
the bespoke gcc-config logic).

The following fragment in kernel `tools/scripts/Makefile.include` looks right 
to me. I don't think it is a workaround. In the future `--gcc-toolchain=` 
should be replaced with `--gcc-install-dir=`

  else ifneq ($(CROSS_COMPILE),)
  # Allow userspace to override CLANG_CROSS_FLAGS to specify their own
  # sysroots and flags or to avoid the GCC call in pure Clang builds.
  ifeq ($(CLANG_CROSS_FLAGS),)
  CLANG_CROSS_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%))
  GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)gcc 2>/dev/null))
  ifneq ($(GCC_TOOLCHAIN_DIR),)
  CLANG_CROSS_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
  CLANG_CROSS_FLAGS += --sysroot=$(shell $(CROSS_COMPILE)gcc -print-sysroot)
  CLANG_CROSS_FLAGS += --gcc-toolchain=$(realpath $(GCC_TOOLCHAIN_DIR)/..)
  endif # GCC_TOOLCHAIN_DIR
  endif # CLANG_CROSS_FLAGS
  CFLAGS += $(CLANG_CROSS_FLAGS)
  AFLAGS += $(CLANG_CROSS_FLAGS)
  endif # CROSS_COMPILE


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

https://reviews.llvm.org/D134454

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


[PATCH] D134947: [analyzer] Fix liveness of Symbols for values in regions reffered by LazyCompoundVal

2022-10-03 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Wow thanks!!

Yeah this matches my understanding of the problem. I still encourage you to 
test it on real-world code before committing, and carefully investigate every 
change in diagnostics, because symbol reaper is very convoluted and filled with 
insane cornercases.




Comment at: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp:461
+bool SymbolReaper::isLazilyCopiedRegion(const MemRegion *MR) const {
+  // TODO: See comment in isLiveRegion.
+  return LazilyCopiedRegionRoots.count(MR->getBaseRegion());

tomasz-kaminski-sonarsource wrote:
> martong wrote:
> > Just out of curiosity, do you have plans to tackle this todo sometime?
> We do not plan to takle it in near future.
Could you add a negative/FIXME test for it?

At a glance I suspect that this TODO is significantly less important for 
`isLiveRegion()` than it is for your new function, so I encourage you to 
explore the possibility of dropping `getBaseRegion()`, even if just a little 
bit and doesn't have to be in this patch.

If a smaller subregion is truly live, any value inside of the base region can 
theoretically be accessed through safe pointer arithmetic. It's very difficult 
to prove that it can't be accessed anymore. Every pointer escape will be a 
potential access.

In your case, however, if the superregion is neither live nor lazily copied, 
the information outside of the lazily copied subregion is truly lost, there's 
literally nothing the program can do to recover it.



Comment at: clang/test/Analysis/trivial-copy-struct.cpp:98
+  // w->head.next and n->next are equal
+  clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
+}

martong wrote:
> 
Do you know what's causing this to not work? Is this a regression or just never 
worked?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134947

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


[PATCH] D134788: [ARM64EC][clang-cl] Add /arm64EC flag

2022-10-03 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I think we want to test both that the warning isn't triggered when --target 
isn't specified, and that the warning is triggered when --target is specified.




Comment at: clang/test/Driver/cl-options.c:787
+// ARM64EC: "-triple" "arm64ec-pc-windows-msvc19.20.0"
+// ARM64EC-NOT: /arm64EC has been overridden by specified target
+

I think the ARM64EC-NOT might be in the wrong place?  I think the warning would 
show up before the final command line, not after it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134788

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


[clang] def48ca - [test] Clean up Driver/baremetal.cpp

2022-10-03 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-10-03T15:35:18-07:00
New Revision: def48cae45a5085b7759f2be71768e27718b901a

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

LOG: [test] Clean up Driver/baremetal.cpp

* Remove -no-canonical-prefixes. See 980679981fbc311bc07f8cd23e3739fd56c22d2a
* Test a.out and %t.out in few tests and remove excess `-o %t.o`
* Avoid wrapping lines too aggresstively
* Replace `"{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}"` with 
`ld{{(.exe)?}}"`. The new pattern supports more CLANG_DEFAULT_LINKER.

Added: 


Modified: 
clang/test/Driver/baremetal.cpp

Removed: 




diff  --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index 53c666d3a91a9..ac99089432477 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -1,125 +1,103 @@
 // UNSUPPORTED: system-windows
 
-// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target armv6m-none-eabi \
+// RUN: %clang %s -### --target=armv6m-none-eabi -o %t.out 2>&1 \
 // RUN: -T semihosted.lds \
 // RUN: -L some/directory/user/asked/for \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-C %s
-// CHECK-V6M-C: "[[PREFIX_DIR:.*]]{{[/\\]+}}{{[^/^\\]+}}{{[/\\]+}}clang{{.*}}" 
"-cc1" "-triple" "thumbv6m-none-unknown-eabi"
+// CHECK-V6M-C:  "-cc1" "-triple" "thumbv6m-none-unknown-eabi"
 // CHECK-V6M-C-SAME: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-C-SAME: "-isysroot" "[[SYSROOT:[^"]*]]"
 // CHECK-V6M-C-SAME: "-internal-isystem" 
"[[SYSROOT]]{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECk-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include"
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
+// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" 
"-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
-// CHECK-V6M-C-SAME: "-o" "{{.*}}.o"
+// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" "-o" 
"{{.*}}.tmp.out"
 
-// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target armv6m-none-eabi \
-// RUN: -nostdlibinc -nobuiltininc \
-// RUN: --sysroot=%S/Inputs/baremetal_arm \
-// RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
-// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target armv6m-none-eabi \
-// RUN: -nostdinc \
-// RUN: --sysroot=%S/Inputs/baremetal_arm \
-// RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBINC %s
+// RUN: %clang %s -### --target=armv6m-none-eabi -nostdlibinc -nobuiltininc 
2>&1 \
+// RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
+// RUN: %clang %s -### --target=armv6m-none-eabi -nostdinc 2>&1 \
+// RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-LIBINC %s
 // CHECK-V6M-LIBINC-NOT: "-internal-isystem"
 
-// RUN: %clang -no-canonical-prefixes -rtlib=compiler-rt %s -### -o %t.o 2>&1 \
-// RUN: -target armv7m-vendor-none-eabi \
+// RUN: %clang %s -### --target=armv7m-vendor-none-eabi -rtlib=compiler-rt 
2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:   | FileCheck --check-prefix=CHECK-ARMV7M-PER-TARGET %s
 // CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
 // CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-ARMV7M-PER-TARGET: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
 // CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-ARMV7M-PER-TARGET: 
"-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
 // CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
-// CHECK-ARMV7M-PER-TARGET: "-o" "{{.*}}.o"
 
-// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -target armv6m-none-eabi \
-// RUN: --sysroot=%S/Inputs/baremetal_arm \
-// RUN:   | FileCheck --check-prefix=CHECK-V6M-DEFAULTCXX %s
+// RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
+// RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck 
--check-prefix=CHECK-V6M-DEFAULTCXX %s
 // CHECK-V6M-DEFAULTCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 

[PATCH] D135115: [clang-format] update --files help description

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen created this revision.
ychen added reviewers: MyDeveloperDay, probinson.
Herald added a project: All.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

correlates the option with reponse file concept.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135115

Files:
  clang/docs/ClangFormat.rst


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -69,7 +69,8 @@
 --ferror-limit=  - Set the maximum number of clang-format 
errors to emit
  before stopping (0 = no limit).
  Used only with --dry-run or -n
---files=   - Provide a list of files to run 
clang-format
+--files=   - Accept a list of response files 
(Deprecated. Use
+ 'clang-format @file' if possbile).
 -i - Inplace edit s, if specified.
 --length=- Format a range of this length (in bytes).
  Multiple ranges can be formatted by 
specifying


Index: clang/docs/ClangFormat.rst
===
--- clang/docs/ClangFormat.rst
+++ clang/docs/ClangFormat.rst
@@ -69,7 +69,8 @@
 --ferror-limit=  - Set the maximum number of clang-format errors to emit
  before stopping (0 = no limit).
  Used only with --dry-run or -n
---files=   - Provide a list of files to run clang-format
+--files=   - Accept a list of response files (Deprecated. Use
+ 'clang-format @file' if possbile).
 -i - Inplace edit s, if specified.
 --length=- Format a range of this length (in bytes).
  Multiple ranges can be formatted by specifying
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133817: MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for pod/aggregate passing

2022-10-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

lgtm

In D133817#3794429 , @dblaikie wrote:

> So, I could leave a test case and some comments, or follow-up with a separate 
> fix for the homogenous aggregate issue? I guess it comes down to writing that 
> separate function to do the tests. (would be great to throw some of this at 
> the ABI fuzzer @majnemer had back in the day, at least I think he had an ABI 
> fuzzer of some sort, yeah?)

Right, we did have a record layout fuzzer which worked pretty well. I think it 
only ever ran on a workstation, it relied on custom tools and the like. I think 
it's lost to the sands of time.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133817

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


[PATCH] D134507: [Clang] add missing ClangABICompat check

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D134507#3831951 , @rjmccall wrote:

> DRs do not modify existing language versions.  We can decide as a vendor 
> whether to apply DRs to existing language versions.  The fact that this is a 
> language semantics change makes me think that we should not in this case.

Sounds good to me. @aaron.ballman do you agree? If so, I'll make a follow-up 
patch to make the DRs conditional on C++20.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134507

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


[PATCH] D134688: MSVC AArch64 ABI: Homogeneous aggregates

2022-10-03 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134688

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


[PATCH] D134788: [ARM64EC][clang-cl] Add /arm64EC flag

2022-10-03 Thread chenglin.bi via Phabricator via cfe-commits
bcl5980 added a comment.

In D134788#3830987 , @efriedma wrote:

> Missing testcase for the case where the warning is triggered?

Based on David's comment I remove the test case with specified target.

  Not going to catch much in this change but if someone goes digging into 
target setting they might change it by other means than --target and not 
realise.

If you think that's necessary I can commit a NFC change to add it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134788

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


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

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

Thanks for the explanation, it is good to know the reasons for the current 
direction. Though it still feels like fixing a symptom and not the root cause.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133586

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


[PATCH] D135110: [NFC] [HLSL] Move common metadata to LLVMFrontend

2022-10-03 Thread Chris Bieneman via Phabricator via cfe-commits
beanz created this revision.
beanz added reviewers: python3kgae, tschuett, jdoerfert, bogner, pow2clk, 
tex3d, Anastasia, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: All.
beanz requested review of this revision.
Herald added projects: clang, LLVM.

This change pulls some code from the DirectX backend into a new
LLVMFrontendHLSL library to share utility data structures between the
HLSL code generation in Clang and the backend in LLVM.

This is a small refactoring as a first start to get code into the
right structure and get the library built and dependencies correct.

Fixes #58000 (https://github.com/llvm/llvm-project/issues/58000)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135110

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/CodeGen/CMakeLists.txt
  llvm/include/llvm/Frontend/HLSL/HLSLResource.h
  llvm/lib/Frontend/CMakeLists.txt
  llvm/lib/Frontend/HLSL/CMakeLists.txt
  llvm/lib/Frontend/HLSL/HLSLResource.cpp
  llvm/lib/Target/DirectX/CMakeLists.txt
  llvm/lib/Target/DirectX/DXILResource.cpp
  llvm/lib/Target/DirectX/DXILResource.h

Index: llvm/lib/Target/DirectX/DXILResource.h
===
--- llvm/lib/Target/DirectX/DXILResource.h
+++ llvm/lib/Target/DirectX/DXILResource.h
@@ -16,6 +16,7 @@
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Frontend/HLSL/HLSLResource.h"
 #include "llvm/IR/Metadata.h"
 #include 
 
@@ -25,22 +26,6 @@
 
 namespace dxil {
 
-// FIXME: Ultimately this class and some of these utilities should be moved into
-// a new LLVMFrontendHLSL library so that they can be reused in Clang.
-// See issue https://github.com/llvm/llvm-project/issues/58000.
-class FrontendResource {
-  MDNode *Entry;
-
-public:
-  FrontendResource(MDNode *E) : Entry(E) {
-assert(Entry->getNumOperands() == 3 && "Unexpected metadata shape");
-  }
-
-  GlobalVariable *getGlobalVariable();
-  StringRef getSourceType();
-  Constant *getID();
-};
-
 class ResourceBase {
 protected:
   uint32_t ID;
@@ -49,7 +34,7 @@
   uint32_t Space;
   uint32_t LowerBound;
   uint32_t RangeSize;
-  ResourceBase(uint32_t I, FrontendResource R);
+  ResourceBase(uint32_t I, hlsl::FrontendResource R);
 
   void write(LLVMContext , MutableArrayRef Entries);
 
@@ -130,7 +115,7 @@
   void parseSourceType(StringRef S);
 
 public:
-  UAVResource(uint32_t I, FrontendResource R);
+  UAVResource(uint32_t I, hlsl::FrontendResource R);
 
   MDNode *write();
 };
Index: llvm/lib/Target/DirectX/DXILResource.cpp
===
--- llvm/lib/Target/DirectX/DXILResource.cpp
+++ llvm/lib/Target/DirectX/DXILResource.cpp
@@ -18,19 +18,7 @@
 
 using namespace llvm;
 using namespace llvm::dxil;
-
-GlobalVariable *FrontendResource::getGlobalVariable() {
-  return cast(
-  cast(Entry->getOperand(0))->getValue());
-}
-
-StringRef FrontendResource::getSourceType() {
-  return cast(Entry->getOperand(1))->getString();
-}
-
-Constant *FrontendResource::getID() {
-  return cast(Entry->getOperand(2))->getValue();
-}
+using namespace llvm::hlsl;
 
 void Resources::collectUAVs() {
   NamedMDNode *Entry = Mod.getNamedMetadata("hlsl.uavs");
Index: llvm/lib/Target/DirectX/CMakeLists.txt
===
--- llvm/lib/Target/DirectX/CMakeLists.txt
+++ llvm/lib/Target/DirectX/CMakeLists.txt
@@ -32,6 +32,7 @@
   Support
   DirectXInfo
   DXILBitWriter
+  FrontendHLSL
 
   ADD_TO_COMPONENT
   DirectX
Index: llvm/lib/Frontend/HLSL/HLSLResource.cpp
===
--- /dev/null
+++ llvm/lib/Frontend/HLSL/HLSLResource.cpp
@@ -0,0 +1,41 @@
+//===- HLSLResource.cpp - HLSL Resource helper objects ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file This file contains helper objects for working with HLSL Resources.
+///
+//===--===//
+
+#include "llvm/Frontend/HLSL/HLSLResource.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace llvm::hlsl;
+
+GlobalVariable *FrontendResource::getGlobalVariable() {
+  return cast(
+  cast(Entry->getOperand(0))->getValue());
+}
+
+StringRef FrontendResource::getSourceType() {
+  return cast(Entry->getOperand(1))->getString();
+}
+
+Constant *FrontendResource::getID() {
+  return cast(Entry->getOperand(2))->getValue();
+}
+
+FrontendResource::FrontendResource(GlobalVariable *GV, StringRef TypeStr,
+   uint32_t Counter) {
+  auto  = 

[PATCH] D134478: BareMetal: detect usr/include/c++/v1 path in sysroot

2022-10-03 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/test/Driver/baremetal.cpp:77
+// RUN: mkdir -p %T/baremetal_cxx_sysroot/usr/include/c++/v1
+// RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -target armv6m-none-eabi \

Delete unused `-no-canonical-prefixes` and `-o %t.o`

Change legacy `-target ` to `--target=`



Comment at: clang/test/Driver/baremetal.cpp:85
+// CHECK-V6M-LIBCXX-USR-SAME: "-internal-isystem" 
"{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}usr{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-V6M-LIBCXX-USR: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" 
"{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBCXX-USR-SAME: 
"-L{{[^"]*}}{{[/\\]+}}baremetal_cxx_sysroot{{[/\\]+}}lib"

It's not necessary to test the linker name. `-Bstatic` is a good enough 
indicator.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134478

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


[PATCH] D134507: [Clang] add missing ClangABICompat check

2022-10-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

DRs do not modify existing language versions.  We can decide as a vendor 
whether to apply DRs to existing language versions.  The fact that this is a 
language semantics change makes me think that we should not in this case.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134507

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


[PATCH] D135011: Add sin and cos llvm builtins

2022-10-03 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

The titled of this patch should be something like "Add 
__builtin_elementwise_sin and __builtin_elementwise_cos".

Can you explain why this uses a new builtin name instead of overloading the 
existing builtins to work on vectors?  I can imagine reasons why, but I think 
it needs to be explained.  I can't imagine `cos` and `sin` not being 
element-wise operations on a vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D133817: MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for pod/aggregate passing

2022-10-03 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao resigned from this revision.
ayzhao added a comment.

Removing myself as a reviewer as I'm not really familiar with this area.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133817

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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-03 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
void added reviewers: efriedma, kees, serge-sans-paille.
Herald added subscribers: steakhal, martong.
Herald added a reviewer: NoQ.
Herald added a project: All.
void requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Use enums for the strict flex arrays flag so that it's more readable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135107

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -794,7 +794,11 @@
 if (Size.isZero())
   return true;
 
-if (getContext().getLangOpts().StrictFlexArrays >= 2)
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+const FAMKind StrictFlexArraysLevel =
+  getContext().getLangOpts().getStrictFlexArraysLevel();
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+StrictFlexArraysLevel == FAMKind::Incomplete)
   return false;
 
 const AnalyzerOptions  = SVB.getAnalyzerOptions();
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15904,7 +15904,8 @@
 /// We avoid emitting out-of-bounds access warnings for such arrays.
 static bool isFlexibleArrayMemberExpr(Sema , const Expr *E,
   const NamedDecl *ND,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
 
   if (!ND)
 return false;
@@ -15919,7 +15920,9 @@
   // 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...
-  if (StrictFlexArraysLevel >= 2 || Size.uge(2))
+  using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+  if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+  Size.uge(2))
 return false;
 
   const FieldDecl *FD = dyn_cast(ND);
@@ -15981,7 +15984,8 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
-  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+  LangOptions::StrictFlexArraysLevelKind
+StrictFlexArraysLevel = getLangOpts().getStrictFlexArraysLevel();
 
   const NamedDecl *ND = nullptr;
   if (const auto *DRE = dyn_cast(BaseExpr))
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -878,16 +878,20 @@
 /// Determine whether this expression refers to a flexible array member in a
 /// struct. We disable array bounds checks for such members.
 static bool isFlexibleArrayMemberExpr(const Expr *E,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For compatibility with existing code, we treat arrays of length 0 or
   // 1 as flexible array members.
   // FIXME: This is inconsistent with the warning code in SemaChecking. Unify
   // the two mechanisms.
   const ArrayType *AT = E->getType()->castAsArrayTypeUnsafe();
   if (const auto *CAT = dyn_cast(AT)) {
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+
 // FIXME: Sema doesn't treat [1] as a flexible array member if the bound
 // was produced by macro expansion.
-if (StrictFlexArraysLevel >= 2 && CAT->getSize().ugt(0))
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete &&
+CAT->getSize().ugt(0))
   return false;
 // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
 // arrays to be treated as flexible-array-members, we still emit ubsan
@@ -963,7 +967,8 @@
 static llvm::Value *getArrayIndexingBound(CodeGenFunction ,
   const Expr *Base,
   QualType ,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For the vector indexing extension, the bound is the number of elements.
   if (const VectorType *VT = Base->getType()->getAs()) {
 IndexedType = 

[PATCH] D133817: MSVC ABI: Looks like even non-aarch64 uses the MSVC/14 definition for pod/aggregate passing

2022-10-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133817

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


[PATCH] D135099: [C2x] Implement support for nullptr and nullptr_t

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



Comment at: clang/lib/Sema/SemaCast.cpp:2999
+  Self.Diag(SrcExpr.get()->getExprLoc(), diag::err_nullptr_cast)
+  << 0 /*nullptr to type*/ << DestType;
+  SrcExpr = ExprError();

Curious why put the comment after? When we use `butprone-argument-comment` for 
function parameters we put them before. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135099

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


[PATCH] D135093: Revert D135076 "[Clang] Make offloading flags accept '-' and '--'"

2022-10-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay abandoned this revision.
MaskRay added a comment.

Pushed in f6797056fc4163e6fe5bd57bebd19aa7fd83a778


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135093

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


[clang] f679705 - Revert D135076 "[Clang] Make offloading flags accept '-' and '--'"

2022-10-03 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-10-03T14:34:16-07:00
New Revision: f6797056fc4163e6fe5bd57bebd19aa7fd83a778

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

LOG: Revert D135076 "[Clang] Make offloading flags accept '-' and '--'"

This reverts commit 11adae50892e6e94f10ce41bc738a9823a6b3251.
There are multiple aspects this change is not appealing.

* They conflict with JoinedOrSeparate `-o`. The old exception `-objc-*`
  should not be used an excuse.
* We generally want new options to be more rigid and avoid multiple
  spellings.
* If users get used to `-offload-*`, a misspelled `-offload-*` option still
  gets passed as `-o ffloat-*` without being detected.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b6130f341083..0b795184b7bd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -833,7 +833,7 @@ def Xopenmp_target_EQ : JoinedAndSeparate<["-"], 
"Xopenmp-target=">, Group, Flags<[LinkerInput]>,
   HelpText<"Pass -z  to the linker">, MetaVarName<"">,
   Group;
-def offload_link : Flag<["--", "-"], "offload-link">, Group,
+def offload_link : Flag<["--"], "offload-link">, Group,
   HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass  to the linker">, MetaVarName<"">,
@@ -933,7 +933,7 @@ def cuda_include_ptx_EQ : Joined<["--"], 
"cuda-include-ptx=">, Flags<[NoXarchOpt
   HelpText<"Include PTX for the following GPU architecture (e.g. sm_35) or 
'all'. May be specified more than once.">;
 def no_cuda_include_ptx_EQ : Joined<["--"], "no-cuda-include-ptx=">, 
Flags<[NoXarchOption]>,
   HelpText<"Do not include PTX for the following GPU architecture (e.g. sm_35) 
or 'all'. May be specified more than once.">;
-def offload_arch_EQ : Joined<["--", "-"], "offload-arch=">, 
Flags<[NoXarchOption]>,
+def offload_arch_EQ : Joined<["--"], "offload-arch=">, Flags<[NoXarchOption]>,
   HelpText<"CUDA offloading device architecture (e.g. sm_35), or HIP 
offloading target ID in the form of a "
"device architecture followed by target ID features delimited by a 
colon. Each target ID feature "
"is a pre-defined string followed by a plus or minus sign (e.g. 
gfx908:xnack+:sramecc-).  May be "
@@ -945,7 +945,7 @@ def hip_link : Flag<["--"], "hip-link">,
   HelpText<"Link clang-offload-bundler bundles for HIP">;
 def no_hip_rt: Flag<["-"], "no-hip-rt">,
   HelpText<"Do not link against HIP runtime libraries">;
-def no_offload_arch_EQ : Joined<["--", "-"], "no-offload-arch=">, 
Flags<[NoXarchOption]>,
+def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, 
Flags<[NoXarchOption]>,
   HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, 
gfx906) from the list of devices to compile for. "
"'all' resets the list to its default value.">;
 def emit_static_lib : Flag<["--"], "emit-static-lib">,
@@ -1187,7 +1187,7 @@ defm autolink : BoolFOption<"autolink",
 // In the future this option will be supported by other offloading
 // languages and accept other values such as CPU/GPU architectures,
 // offload kinds and target aliases.
-def offload_EQ : CommaJoined<["--", "-"], "offload=">, Flags<[NoXarchOption]>,
+def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
   HelpText<"Specify comma-separated list of offloading target triples (CUDA 
and HIP only)">;
 
 // C++ Coroutines TS
@@ -2626,15 +2626,15 @@ defm openmp_optimistic_collapse : 
BoolFOption<"openmp-optimistic-collapse",
   PosFlag, NegFlag, 
BothFlags<[NoArgumentUnused, HelpHidden]>>;
 def static_openmp: Flag<["-"], "static-openmp">,
   HelpText<"Use the static host OpenMP runtime while linking.">;
-def offload_new_driver : Flag<["--", "-"], "offload-new-driver">, 
Flags<[CC1Option]>, Group,
+def offload_new_driver : Flag<["--"], "offload-new-driver">, 
Flags<[CC1Option]>, Group,
   MarshallingInfoFlag>, HelpText<"Use the new 
driver for offloading compilation.">;
-def no_offload_new_driver : Flag<["--", "-"], "no-offload-new-driver">, 
Flags<[CC1Option]>, Group,
+def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">, 
Flags<[CC1Option]>, Group,
   HelpText<"Don't Use the new driver for offloading compilation.">;
-def offload_device_only : Flag<["--", "-"], "offload-device-only">,
+def offload_device_only : Flag<["--"], "offload-device-only">,
   HelpText<"Only compile for the offloading device.">;
-def offload_host_only : Flag<["--", "-"], "offload-host-only">,
+def offload_host_only : Flag<["--"], "offload-host-only">,
   HelpText<"Only compile for the offloading host.">;
-def 

[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

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

Sorry, but I'll revert this patch shortly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this

2022-10-03 Thread Shu-Chun Weng 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 rG3933c43d9008: [clang] Add cc1 option -fctor-dtor-return-this 
(authored by scw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp

Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
===
--- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
+++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
@@ -6,6 +6,8 @@
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s
 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
 
 // Make sure we attach the 'returned' attribute to the 'this' parameter of
@@ -37,10 +39,15 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
@@ -74,13 +81,23 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
 // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this)
-// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
+// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} 

[PATCH] D133499: [clang]: Add DeclContext::dumpAsDecl().

2022-10-03 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann closed this revision.
tahonermann marked 2 inline comments as done.
tahonermann added a comment.

Pushed, but I forgot to add the `Differential Revision` tag to the commit, so 
closing manually. The changes landed as commit 
4247cdb568eca4c31b14d91105fe5ee140225036 
.




Comment at: clang/lib/AST/ASTDumper.cpp:240
+  // the innerworkings of dyn_cast() do assert that to be the case! Alas,
+  // strange and unfortunate things do occasionally occur that lead to folk
+  // like yourself, dear reader, running a debugger and feeling extraordinarily

erichkeane wrote:
> This gets a little overly coy for our comments...
Aw, I was having fun writing that comment! No problem, I'll sprinkle some 
professional polishing salts on it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133499

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


[clang] 3933c43 - [clang] Add cc1 option -fctor-dtor-return-this

2022-10-03 Thread Shu-Chun Weng via cfe-commits

Author: Shu-Chun Weng
Date: 2022-10-03T14:28:06-07:00
New Revision: 3933c43d9008bb1b151156da92827a109e7963b6

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

LOG: [clang] Add cc1 option -fctor-dtor-return-this

This option forces constructors and non-deleting destructors to return
`this` pointer in C++ ABI (except for Microsoft ABI, on which this flag
has no effect).

This is similar to ARM32, Apple ARM64, or Fuchsia C++ ABI, but can be
applied to any target triple.

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

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/test/CodeGenCXX/constructor-destructor-return-this.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index ddeabfc9d5451..62d0c936c60a5 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -492,6 +492,10 @@ ENUM_CODEGENOPT(ZeroCallUsedRegs, 
llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
 /// Whether to use opaque pointers.
 CODEGENOPT(OpaquePointers, 1, 0)
 
+/// Modify C++ ABI to returning `this` pointer from constructors and
+/// non-deleting destructors. (No effect on Microsoft ABI.)
+CODEGENOPT(CtorDtorReturnThis, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 655bf0d58d8e1..b6130f3410830 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5604,6 +5604,11 @@ def ehcontguard : Flag<["-"], "ehcontguard">,
 def fdenormal_fp_math_f32_EQ : Joined<["-"], "fdenormal-fp-math-f32=">,
Group;
 
+def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
+  HelpText<"Change the C++ ABI to returning `this` pointer from constructors "
+   "and non-deleting destructors. (No effect on Microsoft ABI)">,
+  MarshallingInfoFlag>;
+
 } // let Flags = [CC1Option, NoDriverOption]
 
 
//===--===//

diff  --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index 0768e6581acb8..a600768b20746 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ -105,6 +105,10 @@ class CGCXXABI {
   /// final class will have been taken care of by the caller.
   virtual bool isThisCompleteObject(GlobalDecl GD) const = 0;
 
+  virtual bool constructorsAndDestructorsReturnThis() const {
+return CGM.getCodeGenOpts().CtorDtorReturnThis;
+  }
+
 public:
 
   virtual ~CGCXXABI();
@@ -120,7 +124,13 @@ class CGCXXABI {
   ///
   /// There currently is no way to indicate if a destructor returns 'this'
   /// when called virtually, and code generation does not support the case.
-  virtual bool HasThisReturn(GlobalDecl GD) const { return false; }
+  virtual bool HasThisReturn(GlobalDecl GD) const {
+if (isa(GD.getDecl()) ||
+(isa(GD.getDecl()) &&
+ GD.getDtorType() != Dtor_Deleting))
+  return constructorsAndDestructorsReturnThis();
+return false;
+  }
 
   virtual bool hasMostDerivedReturn(GlobalDecl GD) const { return false; }
 

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index cb97af7ab11ab..c84faf468ea22 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -433,11 +433,7 @@ class ARMCXXABI : public ItaniumCXXABI {
 ItaniumCXXABI(CGM, /*UseARMMethodPtrABI=*/true,
   /*UseARMGuardVarABI=*/true) {}
 
-  bool HasThisReturn(GlobalDecl GD) const override {
-return (isa(GD.getDecl()) || (
-  isa(GD.getDecl()) &&
-  GD.getDtorType() != Dtor_Deleting));
-  }
+  bool constructorsAndDestructorsReturnThis() const override { return true; }
 
   void EmitReturnFromThunk(CodeGenFunction , RValue RV,
QualType ResTy) override;
@@ -468,11 +464,7 @@ class FuchsiaCXXABI final : public ItaniumCXXABI {
   : ItaniumCXXABI(CGM) {}
 
 private:
-  bool HasThisReturn(GlobalDecl GD) const override {
-return isa(GD.getDecl()) ||
-   (isa(GD.getDecl()) &&
-GD.getDtorType() != Dtor_Deleting);
-  }
+  bool constructorsAndDestructorsReturnThis() const override { return true; }
 };
 
 class WebAssemblyCXXABI final : public ItaniumCXXABI {
@@ -486,11 +478,7 @@ class WebAssemblyCXXABI final : public ItaniumCXXABI {
   llvm::Value *Exn) override;
 
 private:
-  bool HasThisReturn(GlobalDecl GD) const override {
-return isa(GD.getDecl()) ||
-   

[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 464815.
MaskRay added a comment.

Use `%if clang-target-64-bits`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/Preprocessor/SOURCE_DATE_EPOCH.c

Index: clang/test/Preprocessor/SOURCE_DATE_EPOCH.c
===
--- /dev/null
+++ clang/test/Preprocessor/SOURCE_DATE_EPOCH.c
@@ -0,0 +1,32 @@
+// RUN: env SOURCE_DATE_EPOCH=0 %clang_cc1 -E %s | FileCheck %s --check-prefix=19700101
+
+// 19700101:  const char date[] = "Jan  1 1970";
+// 19700101-NEXT: const char time[] = "00:00:00";
+// 19700101-NEXT: const char timestamp[] = "Thu Jan  1 00:00:00 1970";
+
+// RUN: env SOURCE_DATE_EPOCH=2147483647 %clang_cc1 -E -Wdate-time %s 2>&1 | FileCheck %s --check-prefix=Y2038
+
+// Y2038:  warning: expansion of date or time macro is not reproducible [-Wdate-time]
+// Y2038:  const char date[] = "Jan 19 2038";
+// Y2038-NEXT: const char time[] = "03:14:07";
+// Y2038-NEXT: const char timestamp[] = "Tue Jan 19 03:14:07 2038";
+
+/// Some 32-bits systems have time64 problems.
+// RUN: %if clang-target-64-bits %{ env SOURCE_DATE_EPOCH=253402300799 %clang_cc1 -E -Wdate-time %s 2>&1 | FileCheck %s --check-prefix=1231 %}
+
+// 1231:  warning: expansion of date or time macro is not reproducible [-Wdate-time]
+// 1231:  const char date[] = "Dec 31 ";
+// 1231-NEXT: const char time[] = "23:59:59";
+// 1231-NEXT: const char timestamp[] = "Fri Dec 31 23:59:59 ";
+
+// RUN: env SOURCE_DATE_EPOCH=253402300800 not %clang_cc1 -E %s 2>&1 | FileCheck %s --check-prefix=TOOBIG
+
+// TOOBIG: error: environment variable 'SOURCE_DATE_EPOCH' ('253402300800') must be a non-negative integer <= 253402300799
+
+// RUN: env SOURCE_DATE_EPOCH=0x0 not %clang_cc1 -E %s 2>&1 | FileCheck %s --check-prefix=NOTDECIMAL
+
+// NOTDECIMAL: error: environment variable 'SOURCE_DATE_EPOCH' ('0x0') must be a non-negative integer <= 253402300799
+
+const char date[] = __DATE__;
+const char time[] = __TIME__;
+const char timestamp[] = __TIMESTAMP__;
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1085,8 +1085,15 @@
 /// the identifier tokens inserted.
 static void ComputeDATE_TIME(SourceLocation , SourceLocation ,
  Preprocessor ) {
-  time_t TT = time(nullptr);
-  struct tm *TM = localtime();
+  time_t TT;
+  std::tm *TM;
+  if (PP.getPreprocessorOpts().SourceDateEpoch) {
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {
+TT = std::time(nullptr);
+TM = std::localtime();
+  }
 
   static const char * const Months[] = {
 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
@@ -1593,22 +1600,24 @@
 Diag(Tok.getLocation(), diag::warn_pp_date_time);
 // MSVC, ICC, GCC, VisualAge C++ extension.  The generated string should be
 // of the form "Ddd Mmm dd hh::mm::ss ", which is returned by asctime.
-
-// Get the file that we are lexing out of.  If we're currently lexing from
-// a macro, dig into the include stack.
-const FileEntry *CurFile = nullptr;
-PreprocessorLexer *TheLexer = getCurrentFileLexer();
-
-if (TheLexer)
-  CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());
-
 const char *Result;
-if (CurFile) {
-  time_t TT = CurFile->getModificationTime();
-  struct tm *TM = localtime();
+if (getPreprocessorOpts().SourceDateEpoch) {
+  time_t TT = *getPreprocessorOpts().SourceDateEpoch;
+  std::tm *TM = std::gmtime();
   Result = asctime(TM);
 } else {
-  Result = "??? ??? ?? ??:??:?? \n";
+  // Get the file that we are lexing out of.  If we're currently lexing from
+  // a macro, dig into the include stack.
+  const FileEntry *CurFile = nullptr;
+  if (PreprocessorLexer *TheLexer = getCurrentFileLexer())
+CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());
+  if (CurFile) {
+time_t TT = CurFile->getModificationTime();
+struct tm *TM = localtime();
+Result = asctime(TM);
+  } else {
+Result = "??? ??? ?? ??:??:?? \n";
+  }
 }
 // Surround the string with " and strip the trailing newline.
 OS << '"' << StringRef(Result).drop_back() << '"';
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -4307,6 +4307,15 @@
 

[clang] 4247cdb - [clang]: Add DeclContext::dumpAsDecl().

2022-10-03 Thread Tom Honermann via cfe-commits

Author: Tom Honermann
Date: 2022-10-03T17:25:44-04:00
New Revision: 4247cdb568eca4c31b14d91105fe5ee140225036

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

LOG: [clang]: Add DeclContext::dumpAsDecl().

This change enables a declaration to be conveniently displayed within
a debugger when only a pointer to its DeclContext is available. For example,
in gdb:
  (gdb) p Ctx
  $1 = (const clang::DeclContext *) 0x14c1a580
  (gdb) p Ctx->dumpAsDecl()
  ClassTemplateSpecializationDecl 0x14c1a540  line:2:8 
struct ct
  `-TemplateArgument type 'int'
`-BuiltinType 0x14bac420 'int'
  $2 = void

In the event that the pointed to DeclContext is invalid (that it has an
invalid DeclKind as a result of a dangling pointer, memory corruption, etc...)
it is not possible to dump its associated declaration. In this case, the
DeclContext will be reported as invalid. For example, in gdb:
  (gdb) p Ctx->dumpAsDecl()
  DeclContext 0x14c1a580 
  $3 = void

Added: 


Modified: 
clang/include/clang/AST/ASTDumper.h
clang/include/clang/AST/DeclBase.h
clang/lib/AST/ASTDumper.cpp
clang/lib/AST/DeclBase.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTDumper.h 
b/clang/include/clang/AST/ASTDumper.h
index a154bc2db3a7..71ac467e5104 100644
--- a/clang/include/clang/AST/ASTDumper.h
+++ b/clang/include/clang/AST/ASTDumper.h
@@ -32,6 +32,7 @@ class ASTDumper : public ASTNodeTraverser {
 
   TextNodeDumper () { return NodeDumper; }
 
+  void dumpInvalidDeclContext(const DeclContext *DC);
   void dumpLookups(const DeclContext *DC, bool DumpDecls);
 
   template 

diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 1332b00232be..8a5f75573095 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1909,6 +1909,10 @@ class DeclContext {
 public:
   ~DeclContext();
 
+  // For use when debugging; hasValidDeclKind() will always return true for
+  // a correctly constructed object within its lifetime.
+  bool hasValidDeclKind() const;
+
   Decl::Kind getDeclKind() const {
 return static_cast(DeclContextBits.DeclKind);
   }
@@ -2530,6 +2534,8 @@ class DeclContext {
   static bool classof(const Decl *D);
   static bool classof(const DeclContext *D) { return true; }
 
+  void dumpAsDecl() const;
+  void dumpAsDecl(const ASTContext *Ctx) const;
   void dumpDeclContext() const;
   void dumpLookups() const;
   void dumpLookups(llvm::raw_ostream , bool DumpDecls = false,

diff  --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp
index 60700f71c4b9..9900efb5a48d 100644
--- a/clang/lib/AST/ASTDumper.cpp
+++ b/clang/lib/AST/ASTDumper.cpp
@@ -19,9 +19,37 @@
 #include "clang/Basic/Module.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/raw_ostream.h"
+
 using namespace clang;
 using namespace clang::comments;
 
+void ASTDumper::dumpInvalidDeclContext(const DeclContext *DC) {
+  NodeDumper.AddChild([=] {
+if (!DC) {
+  ColorScope Color(OS, ShowColors, NullColor);
+  OS << "<<>>";
+  return;
+}
+// An invalid DeclContext is one for which a dyn_cast() from a DeclContext
+// pointer to a Decl pointer would fail an assertion or otherwise fall prey
+// to undefined behavior as a result of an invalid associated DeclKind.
+// Such invalidity is not supposed to happen of course, but, when it does,
+// the information provided below is intended to provide some hints about
+// what might have gone awry.
+{
+  ColorScope Color(OS, ShowColors, DeclKindNameColor);
+  OS << "DeclContext";
+}
+NodeDumper.dumpPointer(DC);
+OS << " <";
+{
+  ColorScope Color(OS, ShowColors, DeclNameColor);
+  OS << "unrecognized Decl kind " << (unsigned)DC->getDeclKind();
+}
+OS << ">";
+  });
+}
+
 void ASTDumper::dumpLookups(const DeclContext *DC, bool DumpDecls) {
   NodeDumper.AddChild([=] {
 OS << "StoredDeclsMap ";
@@ -200,6 +228,31 @@ LLVM_DUMP_METHOD void Decl::dumpColor() const {
   P.Visit(this);
 }
 
+LLVM_DUMP_METHOD void DeclContext::dumpAsDecl() const {
+  dumpAsDecl(nullptr);
+}
+
+LLVM_DUMP_METHOD void DeclContext::dumpAsDecl(const ASTContext *Ctx) const {
+  // By design, DeclContext is required to be a base class of some class that
+  // derives from Decl. Thus, it should always be possible to dyn_cast() from
+  // a DeclContext pointer to a Decl pointer and Decl::castFromDeclContext()
+  // asserts that to be the case. Since this function is intended for use in a
+  // debugger, it performs an additional check in order to prevent a failed
+  // cast and assertion. If that check fails, then the (invalid) DeclContext
+  // is dumped with an indication of its invalidity.
+  if (hasValidDeclKind()) {
+const auto *D = 

[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-10-03 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG69a6417406a1: [clang] Implement divergence for TypedefType 
and UsingType (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133468

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sugar-common-types.cpp

Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -112,3 +112,22 @@
 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')}}
+
+using RPB1 = X1*;
+using RPX1 = RPB1;
+using RPB1 = Y1*; // redeclared
+using RPY1 = RPB1;
+N t28 = *(RPB1){}; // expected-error {{lvalue of type 'Y1' (aka 'int')}}
+auto t29 = 0 ? (RPX1){} : (RPY1){};
+N t30 = t29;  // expected-error {{lvalue of type 'RPB1' (aka 'int *')}}
+N t31 = *t29; // expected-error {{lvalue of type 'B1' (aka 'int')}}
+
+namespace A { using type1 = X1*; };
+namespace C { using A::type1; };
+using UPX1 = C::type1;
+namespace A { using type1 = Y1*; };  // redeclared
+namespace C { using A::type1; }; // redeclared
+using UPY1 = C::type1;
+auto t32 = 0 ? (UPX1){} : (UPY1){};
+N t33 = t32;  // expected-error {{lvalue of type 'C::type1' (aka 'int *')}}
+N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3434,25 +3434,34 @@
 }
 
 TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
- QualType underlying, QualType can)
-: Type(tc, can, toSemanticDependence(underlying->getDependence())),
+ QualType Underlying, QualType can)
+: Type(tc, can, toSemanticDependence(can->getDependence())),
   Decl(const_cast(D)) {
   assert(!isa(can) && "Invalid canonical type");
+  TypedefBits.hasTypeDifferentFromDecl = !Underlying.isNull();
+  if (!typeMatchesDecl())
+*getTrailingObjects() = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return getDecl()->getUnderlyingType();
+  return typeMatchesDecl() ? Decl->getUnderlyingType()
+   : *getTrailingObjects();
 }
 
 UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
  QualType Canon)
-: Type(Using, Canon, toSemanticDependence(Underlying->getDependence())),
+: Type(Using, Canon, toSemanticDependence(Canon->getDependence())),
   Found(const_cast(Found)) {
-  assert(Underlying == getUnderlyingType());
+  UsingBits.hasTypeDifferentFromDecl = !Underlying.isNull();
+  if (!typeMatchesDecl())
+*getTrailingObjects() = Underlying;
 }
 
 QualType UsingType::getUnderlyingType() const {
-  return QualType(cast(Found->getTargetDecl())->getTypeForDecl(), 0);
+  return typeMatchesDecl()
+ ? QualType(
+   cast(Found->getTargetDecl())->getTypeForDecl(), 0)
+ : *getTrailingObjects();
 }
 
 QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1543,10 +1543,14 @@
 
 void TextNodeDumper::VisitUsingType(const UsingType *T) {
   dumpDeclRef(T->getFoundDecl());
+  if (!T->typeMatchesDecl())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
   dumpDeclRef(T->getDecl());
+  if (!T->typeMatchesDecl())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
Index: clang/lib/AST/JSONNodeDumper.cpp
===
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -530,6 +530,14 @@
 
 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
+  if (!TT->typeMatchesDecl())
+JOS.attribute("type", createQualType(TT->desugar()));
+}
+
+void JSONNodeDumper::VisitUsingType(const UsingType *TT) {
+  JOS.attribute("decl", createBareDeclRef(TT->getFoundDecl()));
+  if (!TT->typeMatchesDecl())
+JOS.attribute("type", createQualType(TT->desugar()));
 }
 
 void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
Index: 

[clang] 69a6417 - [clang] Implement divergence for TypedefType and UsingType

2022-10-03 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-10-03T23:23:58+02:00
New Revision: 69a6417406a1b0316a1fa6aeb63339d0e1d2abbd

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

LOG: [clang] Implement divergence for TypedefType and UsingType

With this patch, TypedefTypes and UsingTypes can have an
underlying type which diverges from their corresponding
declarations.

For the TypedefType case, this can be seen when getting
the common sugared type between two redeclarations with
different sugar.

For both cases, this will become important as resugaring
is implemented, as this will allow us to resugar these
when they were dependent before instantiation.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/JSONNodeDumper.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/AST/Type.cpp
clang/test/SemaCXX/sugar-common-types.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 787e4234d4ea9..c4954f0d11a3d 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -246,6 +246,7 @@ class ASTContext : public RefCountedBase {
 TemplateSpecializationTypes;
   mutable llvm::FoldingSet ParenTypes{GeneralTypesLog2InitSize};
   mutable llvm::FoldingSet UsingTypes;
+  mutable llvm::FoldingSet TypedefTypes;
   mutable llvm::FoldingSet ElaboratedTypes{
   GeneralTypesLog2InitSize};
   mutable llvm::FoldingSet DependentNameTypes;

diff  --git a/clang/include/clang/AST/JSONNodeDumper.h 
b/clang/include/clang/AST/JSONNodeDumper.h
index c0c902da7c0d9..bff72419c8f3a 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -209,6 +209,7 @@ class JSONNodeDumper
   void Visit(const APValue , QualType Ty);
 
   void VisitTypedefType(const TypedefType *TT);
+  void VisitUsingType(const UsingType *TT);
   void VisitFunctionType(const FunctionType *T);
   void VisitFunctionProtoType(const FunctionProtoType *T);
   void VisitRValueReferenceType(const ReferenceType *RT);

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 434cbbbd10011..b7ef891f97d81 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1807,6 +1807,24 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 unsigned IsUnqual : 1; // If true: typeof_unqual, else: typeof
   };
 
+  class UsingBitfields {
+friend class UsingType;
+
+unsigned : NumTypeBits;
+
+/// True if the underlying type is 
diff erent from the declared one.
+unsigned hasTypeDifferentFromDecl : 1;
+  };
+
+  class TypedefBitfields {
+friend class TypedefType;
+
+unsigned : NumTypeBits;
+
+/// True if the underlying type is 
diff erent from the declared one.
+unsigned hasTypeDifferentFromDecl : 1;
+  };
+
   class SubstTemplateTypeParmTypeBitfields {
 friend class SubstTemplateTypeParmType;
 
@@ -1897,6 +1915,8 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 AttributedTypeBitfields AttributedTypeBits;
 AutoTypeBitfields AutoTypeBits;
 TypeOfBitfields TypeOfBits;
+TypedefBitfields TypedefBits;
+UsingBitfields UsingBits;
 BuiltinTypeBitfields BuiltinTypeBits;
 FunctionTypeBitfields FunctionTypeBits;
 ObjCObjectTypeBitfields ObjCObjectTypeBits;
@@ -4476,9 +4496,12 @@ class UnresolvedUsingType : public Type {
   }
 };
 
-class UsingType : public Type, public llvm::FoldingSetNode {
+class UsingType final : public Type,
+public llvm::FoldingSetNode,
+private llvm::TrailingObjects {
   UsingShadowDecl *Found;
   friend class ASTContext; // ASTContext creates these.
+  friend TrailingObjects;
 
   UsingType(const UsingShadowDecl *Found, QualType Underlying, QualType Canon);
 
@@ -4487,21 +4510,31 @@ class UsingType : public Type, public 
llvm::FoldingSetNode {
   QualType getUnderlyingType() const;
 
   bool isSugared() const { return true; }
+
+  // This always has the 'same' type as declared, but not necessarily 
identical.
   QualType desugar() const { return getUnderlyingType(); }
 
-  void Profile(llvm::FoldingSetNodeID ) { Profile(ID, Found); }
-  static void Profile(llvm::FoldingSetNodeID ,
-  const UsingShadowDecl *Found) {
+  // Internal helper, for debugging purposes.
+  bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }
+
+  void 

[PATCH] D134688: MSVC AArch64 ABI: Homogeneous aggregates

2022-10-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping on this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134688

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


[PATCH] D135025: [clang][Interp] Support base class constructors

2022-10-03 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I realize it is not directly related but I don't see it in the test suite 
(maybe I missed it) but also delegating constructors, default member 
initializaers Vs mem-init list (mem-init list has priority) and mem-init list 
items out of order of initialization.




Comment at: clang/test/AST/Interp/records.cpp:165
+
+class A : public Base {
+public:

How about also testing `private` and `virtual` as well as multiple bases.


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

https://reviews.llvm.org/D135025

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

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



Comment at: clang/test/CodeGen/amdgcn-control-constants.c:8
+
+// GFX90A: @__oclc_daz_opt = linkonce_odr hidden local_unnamed_addr 
addrspace(4) constant i8 0, align 1
+// GFX90A: @__oclc_wavefrontsize64 = linkonce_odr hidden local_unnamed_addr 
addrspace(4) constant i8 1, align 1

yaxunl wrote:
> yaxunl wrote:
> > need an OpenCL test for -cl-denorms-are-zero
> still missing this test, and some other tests for -cl-* options as commented 
> below.
> 
> Also, missing a HIP test for -ffast-math
The cc1 math options tested individually should be enabled by `-ffast-math`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D111000: [clang-format] allow clang-format to be passed a file of filenames so we can add a regression suite of "clean clang-formatted files" from LLVM

2022-10-03 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Response files should work for all our tools, I think?

Keeping the option is fine with me, but the description needs some improvement. 
 @ychen


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111000

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


[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this

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



Comment at: clang/include/clang/Driver/Options.td:5608
+def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
+  HelpText<"Change the C++ ABI to returning `this` pointer from constructors "
+   "and non-deleting destructors. (No effect on Microsoft ABI.)">,

MaskRay wrote:
> scw wrote:
> > MaskRay wrote:
> > > If you use Itanium C++ ABI, it's clear it doesn't change Microsoft ABI.
> > > 
> > > The convention for HelpText is to omit the trailing period.
> > I was gonna do that but realized the change actually apply to all C++ ABIs 
> > (I changed CGCXXABI). It's just Microsoft overrides the same method I 
> > changed making it a no-op.
> Not done?
Thanks. This is fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

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


[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this

2022-10-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:495
 
+/// Modify C++ ABI to returning `this` pointer from constructors and
+/// non-deleting destructors. (No effect on Microsoft ABI.)

Modify `Itanium C++ ABI` and delete ` (No effect on Microsoft ABI.)`



Comment at: clang/include/clang/Driver/Options.td:5608
+def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
+  HelpText<"Change the C++ ABI to returning `this` pointer from constructors "
+   "and non-deleting destructors. (No effect on Microsoft ABI.)">,

scw wrote:
> MaskRay wrote:
> > If you use Itanium C++ ABI, it's clear it doesn't change Microsoft ABI.
> > 
> > The convention for HelpText is to omit the trailing period.
> I was gonna do that but realized the change actually apply to all C++ ABIs (I 
> changed CGCXXABI). It's just Microsoft overrides the same method I changed 
> making it a no-op.
Not done?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

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


[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this

2022-10-03 Thread Shu-Chun Weng via Phabricator via cfe-commits
scw marked an inline comment as done.
scw added inline comments.



Comment at: clang/include/clang/Driver/Options.td:5608
+def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
+  HelpText<"Change the C++ ABI to returning `this` pointer from constructors "
+   "and non-deleting destructors. (No effect on Microsoft ABI.)">,

MaskRay wrote:
> If you use Itanium C++ ABI, it's clear it doesn't change Microsoft ABI.
> 
> The convention for HelpText is to omit the trailing period.
I was gonna do that but realized the change actually apply to all C++ ABIs (I 
changed CGCXXABI). It's just Microsoft overrides the same method I changed 
making it a no-op.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-10-03 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/CodeGen/amdgcn-control-constants.c:8
+
+// GFX90A: @__oclc_daz_opt = linkonce_odr hidden local_unnamed_addr 
addrspace(4) constant i8 0, align 1
+// GFX90A: @__oclc_wavefrontsize64 = linkonce_odr hidden local_unnamed_addr 
addrspace(4) constant i8 1, align 1

yaxunl wrote:
> need an OpenCL test for -cl-denorms-are-zero
still missing this test, and some other tests for -cl-* options as commented 
below.

Also, missing a HIP test for -ffast-math


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D119209: [clang] Add cc1 option -fctor-dtor-return-this

2022-10-03 Thread Shu-Chun Weng via Phabricator via cfe-commits
scw updated this revision to Diff 464809.
scw marked 2 inline comments as done.
scw retitled this revision from "Implement -fctor_dtor_return_this ABI option." 
to "[clang] Add cc1 option -fctor-dtor-return-this".

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp

Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
===
--- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
+++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
@@ -6,6 +6,8 @@
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s
 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
 
 // Make sure we attach the 'returned' attribute to the 'this' parameter of
@@ -37,10 +39,15 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
@@ -74,13 +81,23 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
 // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this)
-// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
+// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
 // 

[PATCH] D131963: [libc++] Add custom clang-tidy checks

2022-10-03 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D131963#3811811 , @ldionne wrote:

> I'd be fine with this as-is if it works in the CI.
>
> IIUC, the current blocker for this is that the `ClangConfig.cmake` installed 
> by LLVM is not robust to the dev packages missing. If you do 
> `find_package(Clang 16.0)`, it will error out if the dev packages are not 
> present, since it will try to reference static libraries (and other 
> artifacts) that don't exist and try to create IMPORTED targets for those. 
> @smeenai @beanz do you know more about that, or do you know someone that 
> does? Do you know who set up the CMake config files so that 
> `find_package(Clang)` would work in the first place? I'd also welcome your 
> input on the `ClangConfigVersion.cmake.in` changes.
>
> Just for the context, what we're trying to do here is simply use 
> `clang-tidy`'s development packages from the libc++ build to add our own 
> custom clang-tidy checks.
>
> Accepting because this LGTM, although we do have some stuff to resolve before 
> this can be shipped.

IIRC, the intended solution was to use `LLVM_DISTRIBUTION_COMPONENTS` 
(https://llvm.org/docs/BuildingADistribution.html). When you use that option, 
the generated CMake package files (at least in the install tree; I'm not sure 
about the ones in the build tree) should only contain imported targets that 
were part of your distribution. Multi-distribution support extends this even 
further, where the file defining the imported targets for a distribution is 
only imported if it's present, so things should work as expected both with and 
without the dev packages. Is that workable for your use case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131963

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


[PATCH] D119209: Implement -fctor_dtor_return_this ABI option.

2022-10-03 Thread Shu-Chun Weng via Phabricator via cfe-commits
scw updated this revision to Diff 464801.
scw added a comment.

Remove unnecessary curly braces.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp

Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
===
--- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
+++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
@@ -6,6 +6,8 @@
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s
 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
 
 // Make sure we attach the 'returned' attribute to the 'this' parameter of
@@ -37,10 +39,15 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
@@ -74,13 +81,23 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
 // CHECKARM-LABEL: define{{.*}} %class.C* @_ZThn8_N1CD1Ev(%class.C* noundef %this)
-// CHECKARM-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
+// CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZThn16_N1CD1Ev(%class.C* noundef %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
 // CHECKARM-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this)
+// 

[PATCH] D119209: Implement -fctor_dtor_return_this ABI option.

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

> Implement -fctor_dtor_return_this ABI option.

Typo in the subject. I'd use: `Add cc1 option -fctor-dtor-return-this`




Comment at: clang/include/clang/Driver/Options.td:5608
+def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
+  HelpText<"Change the C++ ABI to returning `this` pointer from constructors "
+   "and non-deleting destructors. (No effect on Microsoft ABI.)">,

If you use Itanium C++ ABI, it's clear it doesn't change Microsoft ABI.

The convention for HelpText is to omit the trailing period.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6312
   Args.AddLastArg(CmdArgs, options::OPT_malign_double);
+  Args.AddLastArg(CmdArgs, options::OPT_fctor_dtor_return_this);
   Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);

Clang.cpp handles driver options. Since the option is no longer a driver 
option, this should be dropped.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

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


[PATCH] D119209: Implement -fctor_dtor_return_this ABI option.

2022-10-03 Thread Shu-Chun Weng via Phabricator via cfe-commits
scw updated this revision to Diff 464793.
scw retitled this revision from "Implement -mctor_dtor_return_this ABI option.  
 " to "Implement -fctor_dtor_return_this ABI 
option.".
scw edited the summary of this revision.
scw added a comment.

- Made the option cc1-only (invoke through -Xclang).
- Changed the name to -f... from -m...
- Remove mentioning of Itanium ABI--it applies to all C++ ABIs but is 
overridden by the Microsoft one.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119209

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/constructor-destructor-return-this.cpp

Index: clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
===
--- clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
+++ clang/test/CodeGenCXX/constructor-destructor-return-this.cpp
@@ -6,6 +6,8 @@
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia | FileCheck --check-prefix=CHECKFUCHSIA %s
 //RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=i686-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKI686RET %s
+//RUN: %clang_cc1 -no-opaque-pointers %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fctor-dtor-return-this | FileCheck --check-prefix=CHECKAARCH64RET %s
 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
 
 // Make sure we attach the 'returned' attribute to the 'this' parameter of
@@ -37,10 +39,15 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} returned{{[^,]*}} %this)
+
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
+// CHECKI686RET-LABEL: define{{.*}} %class.B* @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
 
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
 // CHECKIOS5-LABEL: define{{.*}} %class.B* @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* noundef %i)
@@ -74,13 +81,23 @@
 // CHECKGEN-LABEL: define{{.*}} void @_ZN1CD0Ev(%class.C* {{[^,]*}} %this)
 // CHECKGEN-LABEL: define{{.*}} void @_ZThn8_N1CD0Ev(%class.C* noundef %this)
 
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
-// CHECKARM-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC2EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CC1EPiPc(%class.C* {{[^,]*}} returned{{[^,]*}} %this, i32* noundef %i, i8* noundef %c)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD2Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
+// CHECKARM-LABEL,CHECKAARCH64RET-LABEL: define{{.*}} %class.C* @_ZN1CD1Ev(%class.C* {{[^,]*}} returned{{[^,]*}} %this)
 // CHECKARM-LABEL: define{{.*}} %class.C* 

[PATCH] D135099: [C2x] Implement support for nullptr and nullptr_t

2022-10-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/AST/PrettyPrinter.h:68
 SuppressDefaultTemplateArgs(true), Bool(LO.Bool),
-Nullptr(LO.CPlusPlus11), Restrict(LO.C99), Alignof(LO.CPlusPlus11),
+Nullptr(LO.CPlusPlus11), NullptrTypeInNamespace(LO.CPlusPlus),
+Restrict(LO.C99), Alignof(LO.CPlusPlus11),

Does Nullptr here not have to change?  Shouldn't we care to use the "nullptr" 
in C mode instead of '0' now?



Comment at: clang/include/clang/AST/PrettyPrinter.h:201
+  /// Whether 'nullptr_t' is in namespace 'std' or not.
+  unsigned NullptrTypeInNamespace;
+

Is there a reason this isn't a bitfield as well?



Comment at: clang/include/clang/Basic/TokenKinds.def:393
 CXX11_KEYWORD(noexcept  , 0)
-CXX11_KEYWORD(nullptr   , 0)
+CXX11_KEYWORD(nullptr   , KEYC2X)
 CXX11_KEYWORD(static_assert , KEYMSCOMPAT|KEYC2X)

Its a shame we have to do this... the CXX11_KEYWORD (and presumably the 
reverse) is used for 'future' diagnostics IIRC.  So not having this as a 
C2X_KEYWORD means we lose the 'future keyword' diagnostics, right?



Comment at: clang/lib/Sema/SemaExpr.cpp:8730
+  //   result also has that type.
+  if (LHSTy->isNullPtrType() && Context.hasSameType(LHSTy, RHSTy))
+return ResTy;

what does this do with the GNU ternary-thing?  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135099

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


[PATCH] D135099: [C2x] Implement support for nullptr and nullptr_t

2022-10-03 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: jyknight, efriedma, clang-language-wg.
Herald added a project: All.
aaron.ballman requested review of this revision.
Herald added a project: clang.

This introduces support for `nullptr` and `nullptr_t` in C2x mode. The proposal 
accepted by WG14 is: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm

Note, there are quite a few incompatibilities with the C++ feature in some of 
the edge cases of this feature. Therefore, there are some FIXME comments in 
tests for testing behavior that might change after WG14 has resolved national 
body comments (a process we've not yet started). So this implementation might 
change slightly depending on the resolution of comments. This is called out 
explicitly in the release notes as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135099

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/PrettyPrinter.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/AST/Expr.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Headers/stddef.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/C/C11/n1330.c
  clang/test/C/C2x/n3042.c
  clang/test/Sema/nullptr.c
  clang/test/Sema/static-assert.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1204,7 +1204,13 @@
 
   Introduce the nullptr constant
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm;>N3042
-  No
+  
+Partial
+  Parts of the implementation may be incorrect until WG14 has completed NB comment
+  resolution for incompatibilities with C++ that were discovered. The major use cases
+  and usage patterns should work well, though.
+
+  
 
 
   Memory layout of unions
Index: clang/test/Sema/static-assert.c
===
--- clang/test/Sema/static-assert.c
+++ clang/test/Sema/static-assert.c
@@ -1,11 +1,11 @@
-// RUN: %clang_cc1 -std=c11 -fsyntax-only -verify %s
-// RUN: %clang_cc1 -fms-compatibility -DMS -fsyntax-only -verify=expected,ms %s
-// RUN: %clang_cc1 -std=c99 -pedantic -fsyntax-only -verify=expected,ext %s
+// RUN: %clang_cc1 -std=c11 -Wgnu-folding-constant -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wgnu-folding-constant -DMS -fsyntax-only -verify=expected,ms %s
+// RUN: %clang_cc1 -std=c99 -pedantic -Wgnu-folding-constant -fsyntax-only -verify=expected,ext %s
 // RUN: %clang_cc1 -xc++ -std=c++11 -pedantic -fsyntax-only -verify=expected,ext,cxx %s
 
 _Static_assert("foo", "string is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
 #ifndef __cplusplus
-// expected-error@-2 {{static assertion expression is not an integral constant expression}}
+// expected-warning@-2 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
 #endif
 
 _Static_assert(1, "1 is nonzero"); // ext-warning {{'_Static_assert' is a C11 extension}}
@@ -85,12 +85,12 @@
 _Static_assert(1.0 != 0, "");  // ext-warning {{'_Static_assert' is a C11 extension}}
 _Static_assert(__builtin_strlen("1"), "");  // ext-warning {{'_Static_assert' is a C11 extension}}
 #ifndef __cplusplus
-// ext-warning@-9 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
-// ext-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-9 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 {{expression is not an integer constant expression; folding it to a constant is a GNU extension}}
+// expected-warning@-8 

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

2022-10-03 Thread Joshua Cranmer via Phabricator via cfe-commits
jcranmer-intel added inline comments.



Comment at: clang/lib/AST/Interp/Floating.h:27-29
+  template  struct Repr;
+  template <> struct Repr<32> { using Type = float; };
+  template <> struct Repr<64> { using Type = double; };

tbaeder wrote:
> jcranmer-intel wrote:
> > aaron.ballman wrote:
> > > Er, how will this extend to `long double` where the number of bits is 
> > > rather more difficult?
> > Or `half` and `bfloat`, which are both 16-bit floating-point types?
> I have spent some time with this today and tried to simply always use 
> `APFloat` instead of a primitive type. Unfortunately that doesn't work 
> because what we put on the stack is not the `Floating` (or `Integral`), but 
> the underlying primitive type. So even if we do the final math (in `::add`, 
> etc) via `APFloat`, we need something we can serialize to `char[]` so we can 
> put it on the stack. Do you think that would work?
I don't know enough about the structure of the bytecode interpreter here to say 
for sure, but this smells to me like you're baking in an assumption that every 
primitive target type has a corresponding primitive type on the host. This 
assumption just doesn't hold when it comes to floating point (only two of the 
seven types, `float` and `double`, are generally portable, and even then, there 
be dragons in some corner cases).

If you do need to continue down this route, there are two requirements that 
should be upheld:
* The representation shouldn't assume that the underlying primitive type exists 
on host (bfloat16 and float128 are better test cases here).
* Conversion to/from host primitive types shouldn't be easy to accidentally do.

(Worth repeating again that bit size is insufficient to distinguish floating 
point types: `bfloat` and `half` are both 16-bit, PPC `long double` and IEEE 
754 quad precision are both 128-bit, and x86 `long double` is 80 bits stored as 
96 bits on 32-bit and 128 bits on 64-bit.)


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

https://reviews.llvm.org/D134859

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


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

2022-10-03 Thread Richard Howell via Phabricator via cfe-commits
rmaz added a comment.

In D133586#3831618 , @vsapsai wrote:

> How correct is it to access `isConst`, `isVolatile`, `isRestrict` for 
> `FunctionNoProtoType`? Yes, we can provide some default value but I'm curious 
> if accessing that default value is correct.
>
> For the record, I've tried to fix the same problem in 
> https://reviews.llvm.org/D104963 in a different way.

That was my initial solution as well, but it seemed safer to ensure these 
methods always returned a consistent value without auditing all the possible 
call sites. I agree that it doesn't seem right that these methods are on the 
base class at all if they are only valid in one of the subclasses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133586

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


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

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

How correct is it to access `isConst`, `isVolatile`, `isRestrict` for 
`FunctionNoProtoType`? Yes, we can provide some default value but I'm curious 
if accessing that default value is correct.

For the record, I've tried to fix the same problem in 
https://reviews.llvm.org/D104963 in a different way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133586

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


[PATCH] D134874: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-10-03 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:255-258
+/// \param ForConstraintInstantiation when collecting arguments,
+/// ForConstraintInstantiation indicates we should continue looking when
+/// encountering a lambda generic call operator, and continue looking for
+/// arguments on an enclosing class template.

erichkeane wrote:
> tahonermann wrote:
> > More a question than a review comment: why is `ForConstraintInstantiation` 
> > needed? The behavior it enables seems to me like the behavior that would 
> > always be desired. When would template arguments for such enclosing 
> > templates not be wanted?
> Apparently we DONT always want the full depth.  It is the intent to only get 
> as far back as 'needed' in some cases, and ForConstraintInstantiation causes 
> us to go 'all the way to the TU' as far as I can tell.  TBH, I'm not super 
> clear on it.  I tried at one point just modifying it, and it broke a ton of 
> tests.
Ok, thanks. My guess is that implies bugs elsewhere but that isn't a concern 
for this change!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134874

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


[PATCH] D135012: [clang][Interp] Implement bitwise and operations

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



Comment at: clang/lib/AST/Interp/Integral.h:215
 
+  static bool band(Integral A, Integral B, unsigned OpBits, Integral *R) {
+*R = Integral(A.V & B.V);

Maybe `bitAnd`?



Comment at: clang/test/AST/Interp/literals.cpp:288
+
+  static_assert((1337 & -1) == 1337, "");
+};

Also `0 &` something else should be `0`.

I wonder if there is any value in using binary literals.


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

https://reviews.llvm.org/D135012

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


[PATCH] D134874: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-10-03 Thread Erich Keane 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 rG939a3d22e21f: [Concepts] Fix Concepts on generic lambda in a 
VarTemplateSpecDecl (authored by erichkeane).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D134874?vs=464360=464778#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134874

Files:
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclBase.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/concepts-lambda.cpp

Index: clang/test/SemaTemplate/concepts-lambda.cpp
===
--- clang/test/SemaTemplate/concepts-lambda.cpp
+++ clang/test/SemaTemplate/concepts-lambda.cpp
@@ -13,3 +13,45 @@
   f();
   };
 }
+
+namespace GH57945_2 {
+  template
+concept c = true;
+
+  template
+auto f = [](auto... args) requires c  {
+};
+
+  template 
+  auto f2 = [](auto... args)
+requires (sizeof...(args) > 0)
+  {};
+
+  void g() {
+  f();
+  f2(5.0);
+  }
+}
+
+namespace GH57958 {
+  template concept C = true;
+  template constexpr bool v = [](C auto) { return true; }(0);
+  int _ = v<0>;
+}
+namespace GH57958_2 {
+  template concept C = true;
+  template constexpr bool v = [](C auto...) { return true; }(0);
+  int _ = v<0>;
+}
+
+namespace GH57971 {
+  template
+concept any = true;
+
+  template
+auto f = [](any auto) {
+};
+
+  using function_ptr = void(*)(int);
+  function_ptr ptr = f;
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -40,13 +40,207 @@
 // Template Instantiation Support
 //===--===/
 
+namespace {
+namespace TemplateInstArgsHelpers {
+struct Response {
+  const Decl *NextDecl = nullptr;
+  bool IsDone = false;
+  bool ClearRelativeToPrimary = true;
+  static Response Done() {
+Response R;
+R.IsDone = true;
+return R;
+  }
+  static Response ChangeDecl(const Decl *ND) {
+Response R;
+R.NextDecl = ND;
+return R;
+  }
+  static Response ChangeDecl(const DeclContext *Ctx) {
+Response R;
+R.NextDecl = Decl::castFromDeclContext(Ctx);
+return R;
+  }
+
+  static Response UseNextDecl(const Decl *CurDecl) {
+return ChangeDecl(CurDecl->getDeclContext());
+  }
+
+  static Response DontClearRelativeToPrimaryNextDecl(const Decl *CurDecl) {
+Response R = Response::UseNextDecl(CurDecl);
+R.ClearRelativeToPrimary = false;
+return R;
+  }
+};
+// Add template arguments from a variable template instantiation.
+Response
+HandleVarTemplateSpec(const VarTemplateSpecializationDecl *VarTemplSpec,
+  MultiLevelTemplateArgumentList ) {
+  // For a class-scope explicit specialization, there are no template arguments
+  // at this level, but there may be enclosing template arguments.
+  if (VarTemplSpec->isClassScopeExplicitSpecialization())
+return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
+
+  // We're done when we hit an explicit specialization.
+  if (VarTemplSpec->getSpecializationKind() == TSK_ExplicitSpecialization &&
+  !isa(VarTemplSpec))
+return Response::Done();
+
+  Result.addOuterTemplateArguments(
+  >getTemplateInstantiationArgs());
+
+  // If this variable template specialization was instantiated from a
+  // specialized member that is a variable template, we're done.
+  assert(VarTemplSpec->getSpecializedTemplate() && "No variable template?");
+  llvm::PointerUnion
+  Specialized = VarTemplSpec->getSpecializedTemplateOrPartial();
+  if (VarTemplatePartialSpecializationDecl *Partial =
+  Specialized.dyn_cast()) {
+if (Partial->isMemberSpecialization())
+  return Response::Done();
+  } else {
+VarTemplateDecl *Tmpl = Specialized.get();
+if (Tmpl->isMemberSpecialization())
+  return Response::Done();
+  }
+  return Response::DontClearRelativeToPrimaryNextDecl(VarTemplSpec);
+}
+
+// If we have a template template parameter with translation unit context,
+// then we're performing substitution into a default template argument of
+// this template template parameter before we've constructed the template
+// that will own this template template parameter. In this case, we
+// use empty template parameter lists for all of the outer templates
+// to avoid performing any substitutions.
+Response
+HandleDefaultTempArgIntoTempTempParam(const TemplateTemplateParmDecl *TTP,
+  MultiLevelTemplateArgumentList ) {
+  for (unsigned I = 

[clang] 939a3d2 - [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-10-03 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-10-03T12:44:21-07:00
New Revision: 939a3d22e21f80246fc6a417da7193c0b93a7a44

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

LOG: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

As fallout of the Deferred Concept Instantiation patch (babdef27c5), we
got a number of reports of a regression, where we asserted when
instantiating a constraint on a generic lambda inside of a variable
template. See: https://github.com/llvm/llvm-project/issues/57958

The problem was that getTemplateInstantiationArgs function only walked
up declaration contexts, and missed that this is not necessarily the
case with a lambda (which can ALSO be in a separate context).

This patch refactors the getTemplateInstantiationArgs function in a way
that is hopefully more readable, and fixes the problem with the concepts
on a generic lambda.

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

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/DeclBase.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/SemaTemplate/concepts-lambda.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index ffc360fa65868..1332b00232bef 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -474,6 +474,9 @@ class alignas(8) Decl {
 
   bool isInStdNamespace() const;
 
+  // Return true if this is a FileContext Decl.
+  bool isFileContextDecl() const;
+
   ASTContext () const LLVM_READONLY;
 
   /// Helper to get the language options from the ASTContext.

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ae74896f6201..74735fb8d07c1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9053,7 +9053,7 @@ class Sema final {
   MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
   const NamedDecl *D, const TemplateArgumentList *Innermost = nullptr,
   bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
-  bool LookBeyondLambda = false, bool IncludeContainingStruct = false);
+  bool ForConstraintInstantiation = false);
 
   /// A context in which code is being synthesized (where a source location
   /// alone is not sufficient to identify the context). This covers template

diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 6c6ffc8c45716..e06235392af8e 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -397,6 +397,11 @@ bool Decl::isInStdNamespace() const {
   return DC && DC->isStdNamespace();
 }
 
+bool Decl::isFileContextDecl() const {
+  const auto *DC = dyn_cast(this);
+  return DC && DC->isFileContext();
+}
+
 TranslationUnitDecl *Decl::getTranslationUnitDecl() {
   if (auto *TUD = dyn_cast(this))
 return TUD;

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 6ad418599d368..d8dadb38758b2 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -505,9 +505,10 @@ Sema::SetupConstraintCheckingTemplateArgumentsAndScope(
   // Collect the list of template arguments relative to the 'primary' template.
   // We need the entire list, since the constraint is completely uninstantiated
   // at this point.
-  MLTAL = getTemplateInstantiationArgs(FD, nullptr, /*RelativeToPrimary*/ true,
-   /*Pattern*/ nullptr,
-   /*LookBeyondLambda*/ true);
+  MLTAL = getTemplateInstantiationArgs(FD, /*Innermost=*/nullptr,
+   /*RelativeToPrimary=*/true,
+   /*Pattern=*/nullptr,
+   /*ForConstraintInstantiation=*/true);
   if (SetupConstraintScope(FD, TemplateArgs, MLTAL, Scope))
 return {};
 
@@ -581,9 +582,9 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 static unsigned CalculateTemplateDepthForConstraints(Sema ,
  const NamedDecl *ND) {
   MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
-  ND, nullptr, /*RelativeToPrimary*/ true,
-  /*Pattern*/ nullptr,
-  /*LookBeyondLambda*/ true, /*IncludeContainingStruct*/ true);
+  ND, /*Innermost=*/nullptr, /*RelativeToPrimary=*/true,
+  /*Pattern=*/nullptr,
+  /*ForConstraintInstantiation=*/true);
   return MLTAL.getNumSubstitutedLevels();
 }
 
@@ -724,6 +725,12 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
 Record = Method->getParent();
   }
   

[PATCH] D126481: [analyzer] Handle SymbolCast in SValBuilder

2022-10-03 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@martong

> So, the intersection should be empty in the above mentioned ambiguous case, 
> shouldn't' it?

No. My current implementation doesn't contain this check in ConstraintAssignor 
in favor of the solution simplification. It'll be added in the next patches.

But still I think, this solution is not accomplished. Consider next. Say, 
symbol `(char)(int x)` is associated to the range `[42, 42]`, and can be 
simplified to constant `42 of char`. And `(int x)` is associated to the range 
`[43, 43]` Your patch will omit looking into the symbol itself and unwrap it 
starting visiting the operand instead. Thus, it will return the constant 43 for 
`(int x)`.
Moreover, if `(int x)` is 43, it will contradict to 42 (aka infeasible state). 
We also have no decision what to return in this case.

For me, this is really uncertain patch that I'm not 100% sure in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126481

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


[PATCH] D134791: [clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExpr

2022-10-03 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

@aaron.ballman : gentle ping :-)


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

https://reviews.llvm.org/D134791

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


[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

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

Another idea is to reject multiple `-o` if some are used as the `Joined` form. 
Note: multiple `Separate` `-o` should be allowed.
It will not catch `-offload-*` when `-o output` is not specified, but is 
probably useful enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-10-03 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 464774.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133468

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sugar-common-types.cpp

Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -112,3 +112,22 @@
 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')}}
+
+using RPB1 = X1*;
+using RPX1 = RPB1;
+using RPB1 = Y1*; // redeclared
+using RPY1 = RPB1;
+N t28 = *(RPB1){}; // expected-error {{lvalue of type 'Y1' (aka 'int')}}
+auto t29 = 0 ? (RPX1){} : (RPY1){};
+N t30 = t29;  // expected-error {{lvalue of type 'RPB1' (aka 'int *')}}
+N t31 = *t29; // expected-error {{lvalue of type 'B1' (aka 'int')}}
+
+namespace A { using type1 = X1*; };
+namespace C { using A::type1; };
+using UPX1 = C::type1;
+namespace A { using type1 = Y1*; };  // redeclared
+namespace C { using A::type1; }; // redeclared
+using UPY1 = C::type1;
+auto t32 = 0 ? (UPX1){} : (UPY1){};
+N t33 = t32;  // expected-error {{lvalue of type 'C::type1' (aka 'int *')}}
+N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3434,25 +3434,34 @@
 }
 
 TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
- QualType underlying, QualType can)
-: Type(tc, can, toSemanticDependence(underlying->getDependence())),
+ QualType Underlying, QualType can)
+: Type(tc, can, toSemanticDependence(can->getDependence())),
   Decl(const_cast(D)) {
   assert(!isa(can) && "Invalid canonical type");
+  TypedefBits.hasTypeDifferentFromDecl = !Underlying.isNull();
+  if (!typeMatchesDecl())
+*getTrailingObjects() = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return getDecl()->getUnderlyingType();
+  return typeMatchesDecl() ? Decl->getUnderlyingType()
+   : *getTrailingObjects();
 }
 
 UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
  QualType Canon)
-: Type(Using, Canon, toSemanticDependence(Underlying->getDependence())),
+: Type(Using, Canon, toSemanticDependence(Canon->getDependence())),
   Found(const_cast(Found)) {
-  assert(Underlying == getUnderlyingType());
+  UsingBits.hasTypeDifferentFromDecl = !Underlying.isNull();
+  if (!typeMatchesDecl())
+*getTrailingObjects() = Underlying;
 }
 
 QualType UsingType::getUnderlyingType() const {
-  return QualType(cast(Found->getTargetDecl())->getTypeForDecl(), 0);
+  return typeMatchesDecl()
+ ? QualType(
+   cast(Found->getTargetDecl())->getTypeForDecl(), 0)
+ : *getTrailingObjects();
 }
 
 QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1543,10 +1543,14 @@
 
 void TextNodeDumper::VisitUsingType(const UsingType *T) {
   dumpDeclRef(T->getFoundDecl());
+  if (!T->typeMatchesDecl())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
   dumpDeclRef(T->getDecl());
+  if (!T->typeMatchesDecl())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
Index: clang/lib/AST/JSONNodeDumper.cpp
===
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -530,6 +530,14 @@
 
 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
+  if (!TT->typeMatchesDecl())
+JOS.attribute("type", createQualType(TT->desugar()));
+}
+
+void JSONNodeDumper::VisitUsingType(const UsingType *TT) {
+  JOS.attribute("decl", createBareDeclRef(TT->getFoundDecl()));
+  if (!TT->typeMatchesDecl())
+JOS.attribute("type", createQualType(TT->desugar()));
 }
 
 void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ 

[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

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

In D135076#3831371 , @jhuber6 wrote:

> In D135076#3831363 , @MaskRay wrote:
>
>> My idea is to just disallow `Joined` `-o` when targeting a specific 
>> environment (e.g. when offloading toolchain is used).
>
> This seems difficult as we only know which offloading toolchains are active 
> after we fully construct the `Compilation` in the driver. We could 
> potentially re-parse some options afterwards to do some static checks like 
> this.

I think I'm fine if you want to warning for every Joined `-o` use of 
`ffloading-*`. Created D135093  to revert 
this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D134874: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-10-03 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:255-258
+/// \param ForConstraintInstantiation when collecting arguments,
+/// ForConstraintInstantiation indicates we should continue looking when
+/// encountering a lambda generic call operator, and continue looking for
+/// arguments on an enclosing class template.

tahonermann wrote:
> More a question than a review comment: why is `ForConstraintInstantiation` 
> needed? The behavior it enables seems to me like the behavior that would 
> always be desired. When would template arguments for such enclosing templates 
> not be wanted?
Apparently we DONT always want the full depth.  It is the intent to only get as 
far back as 'needed' in some cases, and ForConstraintInstantiation causes us to 
go 'all the way to the TU' as far as I can tell.  TBH, I'm not super clear on 
it.  I tried at one point just modifying it, and it broke a ton of tests.


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

https://reviews.llvm.org/D134874

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

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

Moving test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGen/amdgcn-control-constants.c
  clang/test/CodeGenCUDA/amdgcn-control-constants.hip

Index: clang/test/CodeGenCUDA/amdgcn-control-constants.hip
===
--- /dev/null
+++ clang/test/CodeGenCUDA/amdgcn-control-constants.hip
@@ -0,0 +1,46 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --check-globals --include-generated-funcs --global-value-regex "__oclc_daz_opt"
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -fcuda-is-device -target-cpu gfx90a -emit-llvm-bc -o %t.bc -DLIBRARY %s
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -fcuda-is-device -target-cpu gfx90a -mlink-builtin-bitcode %t.bc -S -emit-llvm -o - %s | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target
+
+#include "Inputs/cuda.h"
+
+#ifdef LIBRARY
+
+extern unsigned char __constant__ __oclc_daz_opt;
+
+__device__ int foo(void) {
+  return __oclc_daz_opt ? 1 : 0;
+}
+
+#else
+
+extern __device__ int foo(void);
+
+__device__ void bar(void) {
+  foo();
+}
+
+#endif
+//.
+// CHECK: @__oclc_daz_opt = internal local_unnamed_addr addrspace(4) constant i8 0, align 1
+//.
+// CHECK-LABEL: define {{[^@]+}}@_Z3barv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[CALL:%.*]] = call noundef i32 @_Z3foov() #[[ATTR1:[0-9]+]]
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr
+// CHECK-NEXT:[[TMP0:%.*]] = load i8, ptr addrspacecast (ptr addrspace(4) @__oclc_daz_opt to ptr), align 1
+// CHECK-NEXT:[[TOBOOL:%.*]] = icmp ne i8 [[TMP0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = zext i1 [[TOBOOL]] to i64
+// CHECK-NEXT:[[COND:%.*]] = select i1 [[TOBOOL]], i32 1, i32 0
+// CHECK-NEXT:ret i32 [[COND]]
+//
Index: clang/test/CodeGen/amdgcn-control-constants.c
===
--- /dev/null
+++ clang/test/CodeGen/amdgcn-control-constants.c
@@ -0,0 +1,49 @@
+// Check that we generate all the expected default features for the target.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GFX90A
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx1030 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GFX1030
+
+// GFX90A: @__oclc_daz_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX90A: @__oclc_finite_only_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX90A: @__oclc_unsafe_math_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX90A: @__oclc_correctly_rounded_sqrt32 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+// GFX90A: @__oclc_wavefrontsize64 = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i8 1
+// GFX90A: @__oclc_ISA_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 9010
+// GFX90A: @__oclc_ABI_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 400
+
+// GFX1030: @__oclc_daz_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_finite_only_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_unsafe_math_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_correctly_rounded_sqrt32 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+// GFX1030: @__oclc_wavefrontsize64 = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_ISA_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 10048
+// GFX1030: @__oclc_ABI_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 400
+
+// Check that we can override the wavefront features.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx1030 -target-feature +wavefrontsize64 \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WAVEFRONT
+// WAVEFRONT: @__oclc_wavefrontsize64 = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i8 1
+
+// Check that we can enable denormalization at zero.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -fdenormal-fp-math-f32=preserve-sign,preserve-sign \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=DENORM-AT-ZERO
+// DENORM-AT-ZERO: 

[PATCH] D134507: [Clang] add missing ClangABICompat check

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

ping.

To avoid confusion, note that this and D128745 
 are not about C++20 or newer language 
versions. They are implementing DRs which should apply to all language versions 
>= C++11 since the variadic template is involved.

ClangABICompat is used here and in a few other places by D128745 
. If an alternative method is needed, I could 
switch them over all at once in another patch. How about we land this first and 
see how far this goes if it is bad, confusing, etc., feel free to leave a 
comment here or in a bug report, I could address it promptly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134507

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


[PATCH] D134874: [Concepts] Fix Concepts on generic lambda in a VarTemplateSpecDecl

2022-10-03 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision.
tahonermann added a comment.
This revision is now accepted and ready to land.

I think this looks good. I took more time to compare with the current code and 
it looks to me like behavioral consistency is maintained where desired.

I added one comments requesting a change to a comment (to be made when 
committing the changes) and another comment with a question asked to improve my 
own understanding (that might also indicate that some additional comments would 
be helpful).




Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:75-77
+// Add template arguments from a variable template instantiation. For a
+// class-scope explicit specialization, there are no template arguments
+// at this level, but there may be enclosing template arguments.

I think the selected portion of this comment would be better placed inside the 
function before the call to `isClassScopeExplicitSpecialization`.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:255-258
+/// \param ForConstraintInstantiation when collecting arguments,
+/// ForConstraintInstantiation indicates we should continue looking when
+/// encountering a lambda generic call operator, and continue looking for
+/// arguments on an enclosing class template.

More a question than a review comment: why is `ForConstraintInstantiation` 
needed? The behavior it enables seems to me like the behavior that would always 
be desired. When would template arguments for such enclosing templates not be 
wanted?


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

https://reviews.llvm.org/D134874

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


[PATCH] D135011: Add sin and cos llvm builtins

2022-10-03 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Does these support scalable vector types from ARM SVE or RISC-V? I can't 
remember what the rest of the __builtin_elementwise do. I ask because the 
backends will probably crash for them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

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


[PATCH] D135093: Revert D135076 "[Clang] Make offloading flags accept '-' and '--'"

2022-10-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: jhuber6, jdoerfert, JonChesterfield.
Herald added a subscriber: StephenFan.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit 11adae50892e6e94f10ce41bc738a9823a6b3251 
.
There are multiple aspects this change is not appealing.

- They conflict with JoinedOrSeparate `-o`. The old exception `-objc-*` should 
not be used an excuse.
- We generally want new options to be more rigid and avoid multiple spellings.
- A misspelled `--offload-*` option still gets passed as `-o ffloat-*` without 
being detected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135093

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


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -833,7 +833,7 @@
 def z : Separate<["-"], "z">, Flags<[LinkerInput]>,
   HelpText<"Pass -z  to the linker">, MetaVarName<"">,
   Group;
-def offload_link : Flag<["--", "-"], "offload-link">, Group,
+def offload_link : Flag<["--"], "offload-link">, Group,
   HelpText<"Use the new offloading linker to perform the link job.">;
 def Xlinker : Separate<["-"], "Xlinker">, Flags<[LinkerInput, RenderAsInput]>,
   HelpText<"Pass  to the linker">, MetaVarName<"">,
@@ -933,7 +933,7 @@
   HelpText<"Include PTX for the following GPU architecture (e.g. sm_35) or 
'all'. May be specified more than once.">;
 def no_cuda_include_ptx_EQ : Joined<["--"], "no-cuda-include-ptx=">, 
Flags<[NoXarchOption]>,
   HelpText<"Do not include PTX for the following GPU architecture (e.g. sm_35) 
or 'all'. May be specified more than once.">;
-def offload_arch_EQ : Joined<["--", "-"], "offload-arch=">, 
Flags<[NoXarchOption]>,
+def offload_arch_EQ : Joined<["--"], "offload-arch=">, Flags<[NoXarchOption]>,
   HelpText<"CUDA offloading device architecture (e.g. sm_35), or HIP 
offloading target ID in the form of a "
"device architecture followed by target ID features delimited by a 
colon. Each target ID feature "
"is a pre-defined string followed by a plus or minus sign (e.g. 
gfx908:xnack+:sramecc-).  May be "
@@ -945,7 +945,7 @@
   HelpText<"Link clang-offload-bundler bundles for HIP">;
 def no_hip_rt: Flag<["-"], "no-hip-rt">,
   HelpText<"Do not link against HIP runtime libraries">;
-def no_offload_arch_EQ : Joined<["--", "-"], "no-offload-arch=">, 
Flags<[NoXarchOption]>,
+def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, 
Flags<[NoXarchOption]>,
   HelpText<"Remove CUDA/HIP offloading device architecture (e.g. sm_35, 
gfx906) from the list of devices to compile for. "
"'all' resets the list to its default value.">;
 def emit_static_lib : Flag<["--"], "emit-static-lib">,
@@ -1187,7 +1187,7 @@
 // In the future this option will be supported by other offloading
 // languages and accept other values such as CPU/GPU architectures,
 // offload kinds and target aliases.
-def offload_EQ : CommaJoined<["--", "-"], "offload=">, Flags<[NoXarchOption]>,
+def offload_EQ : CommaJoined<["--"], "offload=">, Flags<[NoXarchOption]>,
   HelpText<"Specify comma-separated list of offloading target triples (CUDA 
and HIP only)">;
 
 // C++ Coroutines TS
@@ -2626,15 +2626,15 @@
   PosFlag, NegFlag, 
BothFlags<[NoArgumentUnused, HelpHidden]>>;
 def static_openmp: Flag<["-"], "static-openmp">,
   HelpText<"Use the static host OpenMP runtime while linking.">;
-def offload_new_driver : Flag<["--", "-"], "offload-new-driver">, 
Flags<[CC1Option]>, Group,
+def offload_new_driver : Flag<["--"], "offload-new-driver">, 
Flags<[CC1Option]>, Group,
   MarshallingInfoFlag>, HelpText<"Use the new 
driver for offloading compilation.">;
-def no_offload_new_driver : Flag<["--", "-"], "no-offload-new-driver">, 
Flags<[CC1Option]>, Group,
+def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">, 
Flags<[CC1Option]>, Group,
   HelpText<"Don't Use the new driver for offloading compilation.">;
-def offload_device_only : Flag<["--", "-"], "offload-device-only">,
+def offload_device_only : Flag<["--"], "offload-device-only">,
   HelpText<"Only compile for the offloading device.">;
-def offload_host_only : Flag<["--", "-"], "offload-host-only">,
+def offload_host_only : Flag<["--"], "offload-host-only">,
   HelpText<"Only compile for the offloading host.">;
-def offload_host_device : Flag<["--", "-"], "offload-host-device">,
+def offload_host_device : Flag<["--"], "offload-host-device">,
   HelpText<"Only compile for the offloading host.">;
 def cuda_device_only : Flag<["--"], "cuda-device-only">, 
Alias,
   HelpText<"Compile CUDA code for device only">;


Index: clang/include/clang/Driver/Options.td
===
--- 

[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-03 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

The Windows premerge failure looks relevant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

2022-10-03 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D135076#3831363 , @MaskRay wrote:

> My idea is to just disallow `Joined` `-o` when targeting a specific 
> environment (e.g. when offloading toolchain is used).

This seems difficult as we only know which offloading toolchains are active 
after we fully construct the `Compilation` in the driver. We could potentially 
re-parse some options afterwards to do some static checks like this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

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

In D135076#3831347 , @jhuber6 wrote:

> In D135076#3831340 , @MaskRay wrote:
>
>> In D135076#3831307 , @jhuber6 
>> wrote:
>>
>>> In D135076#3831298 , @MaskRay 
>>> wrote:
>>>
 We really want these `--offload-*` users to stick with one canonical form, 
 not `-offload-*` in some places while `--offload-*` in other places.

 Another angle is that people find `-offload-*` working with a new clang 
 may try `-offload-*` on an old clang and get `-o ffload-*`.

 And `-offload-*` doesn't help misspelled options.
>>>
>>> This is fine, as long as users get more distinct feedback that 
>>> `-offload-arch` isn't doing what they think it does. Normally we'd get some 
>>> error and a helpful suggestion if the option is misspelled, but with `-o` 
>>> options we don't get anything.
>>> My only qualm with the current state is that it's not obvious that 
>>> `-offload-arch` is actually `-o ffload-arch` for most cases.
>>
>> You can make `-oxxx` an error if offloading is used (`-o xxx` is still 
>> allowed). Then no `--offload-*` needs a `-offload-*` form.
>
> The problem here is that the `--offload-*` options are used to enable the 
> offloading toolchain for some targets (e.g. OpenMP). Would a check on `-o' 
> that emits a warning if it matches closely a known option work? E.g. 
> `-offload-arch` would warn that the user may mean `--offload-arch`.

If we don't have `Joined` `-o`, we won't have the option collision problem. But 
we have `Joined` `-o`, and we should not introduce new aliases to collide with 
`-o`.
I am fine if `Joined` `-o` can go away but there are too many uses so such a 
change would be destructive.

My idea is to just disallow `Joined` `-o` when targeting a specific environment 
(e.g. when offloading toolchain is used).

>> This patch probably provides some convenience but regresses other aspects, 
>> and I think it should be reverted.
>
> If you think this should be reverted then I'm fine with it. I would like to 
> see some kind of solution to this problem however, as I have dealt with this 
> problem many times when working with users.

As mentioned, making users stick with more forms instead of all using the 
canonical form will do harm in other aspects.
I have explained these aspects in my previous comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D134928: [Sema] Don't treat a non-null template argument as if it were null.

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



Comment at: clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1-11.cpp:31
 IP<> ip7; // expected-error{{non-type template argument of type 'int *' is 
not a constant expression}}
+IP<(int*)1> ip8; // expected-error {{non-type template argument does not refer 
to any declaration}}
 

rsmith wrote:
> efriedma wrote:
> > erichkeane wrote:
> > > shafik wrote:
> > > > shafik wrote:
> > > > > It looks like in C++17 mode we catch this case: 
> > > > > https://godbolt.org/z/s43oE5qWE
> > > > Another case to check for:
> > > > 
> > > > ```
> > > > IP<(int*)(1-1)> ip9;
> > > > ```
> > > > 
> > > > In C++11 the wording use to allow `integer constant expressions`
> > > The new diagnostic here is unfortunate.  That 'does not refer to any 
> > > declaration' doesn't really let me know that it is illegal because that 
> > > isn't a NPE.  
> > > 
> > > The 'treat it as a null ptr' here is obviously awful, but I find myself 
> > > wondering if we can do better on this diagnostic trivially enough?
> > It's easy enough to use a different message; we just need to detect the 
> > particular case we're considering, print an error, and return NPV_Error.  
> > But I'm not sure what a better diagnostic looks like.   "standard C++ does 
> > not allow using '(int*)1' as a non-type template argument"?  (The fact that 
> > null is allowed isn't really relevant here.)
> > It looks like in C++17 mode we catch this case: 
> > https://godbolt.org/z/s43oE5qWE
> 
> That's diagnosing the cast, not the template argument value. You can get 
> around the cast diagnostic by forcing constant folding with a 
> `__builtin_constant_p` conditional 
> ([example](https://godbolt.org/z/8f8WWTGeM)). Then we diagnose as
> > :7:4: error: non-type template argument refers to subobject '(int 
> > *)1'
> ... which seems like a worse diagnostic than the C++11 one, because it's not 
> even true.

> That's diagnosing the cast, not the template argument value. You can get 
> around the cast diagnostic by forcing constant folding with a 
> `__builtin_constant_p` conditional 
> ([example](https://godbolt.org/z/8f8WWTGeM)). Then we diagnose as
> > :7:4: error: non-type template argument refers to subobject '(int 
> > *)1'
> ... which seems like a worse diagnostic than the C++11 one, because it's not 
> even true.

Great point, I missed that earlier.

My point was that if we are catching this in C++17 mode maybe we can reuse the 
machinery to catch this other modes as well and fix the diagnostic quality as 
well. Although I realize that may not be easy but worth at least understanding. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134928

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


[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

2022-10-03 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D135076#3831340 , @MaskRay wrote:

> In D135076#3831307 , @jhuber6 wrote:
>
>> In D135076#3831298 , @MaskRay 
>> wrote:
>>
>>> We really want these `--offload-*` users to stick with one canonical form, 
>>> not `-offload-*` in some places while `--offload-*` in other places.
>>>
>>> Another angle is that people find `-offload-*` working with a new clang may 
>>> try `-offload-*` on an old clang and get `-o ffload-*`.
>>>
>>> And `-offload-*` doesn't help misspelled options.
>>
>> This is fine, as long as users get more distinct feedback that 
>> `-offload-arch` isn't doing what they think it does. Normally we'd get some 
>> error and a helpful suggestion if the option is misspelled, but with `-o` 
>> options we don't get anything.
>> My only qualm with the current state is that it's not obvious that 
>> `-offload-arch` is actually `-o ffload-arch` for most cases.
>
> You can make `-oxxx` an error if offloading is used (`-o xxx` is still 
> allowed). Then no `--offload-*` needs a `-offload-*` form.

The problem here is that the `--offload-*` options are used to enable the 
offloading toolchain for some targets (e.g. OpenMP). Would a check on `-o' that 
emits a warning if it matches closely a known option work? E.g. `-offload-arch` 
would warn that the user may mean `--offload-arch`.

> This patch probably provides some convenience but regresses other aspects, 
> and I think it should be reverted.

If you think this should be reverted then I'm fine with it. I would like to see 
some kind of solution to this problem however, as I have dealt with this 
problem many times when working with users.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

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

In D135076#3831307 , @jhuber6 wrote:

> In D135076#3831298 , @MaskRay wrote:
>
>> We really want these `--offload-*` users to stick with one canonical form, 
>> not `-offload-*` in some places while `--offload-*` in other places.
>>
>> Another angle is that people find `-offload-*` working with a new clang may 
>> try `-offload-*` on an old clang and get `-o ffload-*`.
>>
>> And `-offload-*` doesn't help misspelled options.
>
> This is fine, as long as users get more distinct feedback that 
> `-offload-arch` isn't doing what they think it does. Normally we'd get some 
> error and a helpful suggestion if the option is misspelled, but with `-o` 
> options we don't get anything.
> My only qualm with the current state is that it's not obvious that 
> `-offload-arch` is actually `-o ffload-arch` for most cases.

You can make `-oxxx` an error if offloading is used (`-o xxx` is still 
allowed). Then no `--offload-*` needs a `-offload-*` form.

This patch probably provides some convenience but regresses other aspects, and 
I think it should be reverted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


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

2022-10-03 Thread Michael Wyman via Phabricator via cfe-commits
mwyman added a comment.

In D131424#3828656 , @mwyman wrote:

> In D131424#3828647 , @ahatanak 
> wrote:
>
>> `-fobjc-arc` is needed to see the assertion fail.
>
> Oops, yep I'll send a patch.

Sent https://reviews.llvm.org/D135091


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131424

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


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

2022-10-03 Thread Michael Wyman via Phabricator via cfe-commits
mwyman created this revision.
mwyman added reviewers: ahatanak, plotfi, dmaclach.
mwyman added a project: clang.
Herald added a project: All.
mwyman requested review of this revision.
Herald added a subscriber: cfe-commits.

This fixes a bug from https://reviews.llvm.org/D131424 that removed the 
implicit `_cmd` parameter as an argument to `objc_direct` method 
implementations. In many cases the generated getter/setter will call 
`objc_getProperty` or `objc_setProperty`, both of which require the selector of 
the getter/setter; since `_cmd` didn't automatically have backing storage, 
attempting to load the address asserted.

This adds an explicit load of the selector, similar to if it's referenced in an 
`objc_direct` method body; since the getter/setter is entirely synthesized, 
there's no reason to preemptively load the selector and store it locally, so 
the value is directly loaded and no additional storage is created for it.

Added a test that triggers the assert prior to the implementation code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135091

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


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,14 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); this also
+// checks that the synthesized method accesses _cmd (or rather loads the
+// selector, as it is an argument to objc_getProperty).
+// CHECK-LABEL: define hidden i8* @"\01-[Root objectProperty]"(
+// CHECK-LABEL: objc_direct_method.cont:
+// CHECK-NEXT: load i8*, i8** @OBJC_SELECTOR_REFERENCES_
+// CHECK: call i8* @objc_getProperty({{.*}})
+
 @interface Foo : Root {
   id __strong _cause_cxx_destruct;
 }
Index: clang/lib/CodeGen/CGObjC.cpp
===
--- clang/lib/CodeGen/CGObjC.cpp
+++ clang/lib/CodeGen/CGObjC.cpp
@@ -1189,8 +1189,17 @@
 // Return (ivar-type) objc_getProperty((id) self, _cmd, offset, true).
 // FIXME: Can't this be simpler? This might even be worse than the
 // corresponding gcc code.
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()), "cmd");
+llvm::Value *cmd;
+if (getterMethod->isDirectMethod()) {
+  // Direct methods do not have the `_cmd` parameter; the selector must be
+  // loaded explicitly. Since it is not otherwise used in the getter, there
+  // is no reason to create a local variable for it.
+  cmd =
+  CGM.getObjCRuntime().GetSelector(*this, getterMethod->getSelector());
+} else {
+  cmd = Builder.CreateLoad(GetAddrOfLocalVar(getterMethod->getCmdDecl()),
+   "cmd");
+}
 llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =
   EmitIvarOffset(classImpl->getClassInterface(), ivar);
@@ -1475,10 +1484,18 @@
 
 // Emit objc_setProperty((id) self, _cmd, offset, arg,
 //   , ).
-llvm::Value *cmd =
-  Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()));
-llvm::Value *self =
-  Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
+llvm::Value *cmd;
+if (setterMethod->isDirectMethod()) {
+  // Direct methods do not have the `_cmd` parameter; the selector must be
+  // loaded explicitly. Since it is not otherwise used in the setter, there
+  // is no reason to create a local variable for it.
+  cmd =
+  CGM.getObjCRuntime().GetSelector(*this, setterMethod->getSelector());
+} else {
+  cmd = Builder.CreateLoad(GetAddrOfLocalVar(setterMethod->getCmdDecl()),
+   "cmd");
+}
+llvm::Value *self = Builder.CreateBitCast(LoadObjCSelf(), VoidPtrTy);
 llvm::Value *ivarOffset =
   EmitIvarOffset(classImpl->getClassInterface(), ivar);
 Address argAddr = GetAddrOfLocalVar(*setterMethod->param_begin());


Index: clang/test/CodeGenObjC/direct-method.m
===
--- clang/test/CodeGenObjC/direct-method.m
+++ clang/test/CodeGenObjC/direct-method.m
@@ -14,6 +14,7 @@
 - (int)getInt __attribute__((objc_direct));
 @property(direct, readonly) int intProperty;
 @property(direct, readonly) int intProperty2;
+@property(direct, readonly) id objectProperty;
 @end
 
 @implementation Root
@@ -167,6 +168,14 @@
 @end
 // CHECK-LABEL: define hidden i32 @"\01-[Root intProperty]"
 
+// Check the synthesized objectProperty calls objc_getProperty(); 

[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

2022-10-03 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D135076#3831298 , @MaskRay wrote:

> We really want these `--offload-*` users to stick with one canonical form, 
> not `-offload-*` in some places while `--offload-*` in other places.
>
> Another angle is that people find `-offload-*` working with a new clang may 
> try `-offload-*` on an old clang and get `-o ffload-*`.
>
> And `-offload-*` doesn't help misspelled options.

This is fine, as long as users get more distinct feedback that `-offload-arch` 
isn't doing what they think it does. Normally we'd get some error and a helpful 
suggestion if the option is misspelled, but with `-o` options we don't get 
anything. My only qualm with the current state is that it's not obvious that 
`-offload-arch` is actually `-o ffload-arch` for most cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D135076: [Clang] Make offloading flags accept '-' and '--'

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

We really want these `--offload-*` users to stick with one canonical form, not 
`-offload-*` in some places while `--offload-*` in other places.

Another angle is that people find `-offload-*` working with a new clang may try 
`-offload-*` on an old clang and get `-o ffload-*`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135076

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


[PATCH] D135011: Add sin and cos llvm builtins

2022-10-03 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 464744.
bob80905 edited the summary of this revision.
bob80905 added a comment.

- add release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135011

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Builtins.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c
  clang/test/SemaCXX/builtins-elementwise-math.cpp

Index: clang/test/SemaCXX/builtins-elementwise-math.cpp
===
--- clang/test/SemaCXX/builtins-elementwise-math.cpp
+++ clang/test/SemaCXX/builtins-elementwise-math.cpp
@@ -59,3 +59,17 @@
   static_assert(!is_const::value);
   static_assert(!is_const::value);
 }
+
+void test_builtin_elementwise_cos() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
+
+void test_builtin_elementwise_sin() {
+  const float a = 42.0;
+  float b = 42.3;
+  static_assert(!is_const::value);
+  static_assert(!is_const::value);
+}
Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -280,6 +280,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_cos(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_cos(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_cos();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_cos(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_cos(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_cos(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_cos(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_floor(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_floor(f);
@@ -322,6 +343,27 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
+void test_builtin_elementwise_sin(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
+
+  struct Foo s = __builtin_elementwise_sin(f);
+  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'float'}}
+
+  i = __builtin_elementwise_sin();
+  // expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
+
+  i = __builtin_elementwise_sin(i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  i = __builtin_elementwise_sin(f, f);
+  // expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
+
+  u = __builtin_elementwise_sin(u);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned int')}}
+
+  uv = __builtin_elementwise_sin(uv);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
+}
+
 void test_builtin_elementwise_trunc(int i, float f, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
 
   struct Foo s = __builtin_elementwise_trunc(f);
Index: clang/test/CodeGen/builtins-elementwise-math.c
===
--- clang/test/CodeGen/builtins-elementwise-math.c
+++ clang/test/CodeGen/builtins-elementwise-math.c
@@ -333,6 +333,22 @@
   vf2 = __builtin_elementwise_ceil(vf1);
 }
 
+void test_builtin_elementwise_cos(float f1, float f2, double d1, double d2,
+  float4 vf1, float4 vf2) {
+  // CHECK-LABEL: define void @test_builtin_elementwise_cos(
+  // CHECK:  [[F1:%.+]] = load float, float* %f1.addr, align 4
+  // CHECK-NEXT:  call float @llvm.cos.f32(float [[F1]])
+  f2 = __builtin_elementwise_cos(f1);
+
+  // CHECK:  [[D1:%.+]] = load double, double* %d1.addr, align 8
+  // CHECK-NEXT: call double @llvm.cos.f64(double [[D1]])
+  d2 = __builtin_elementwise_cos(d1);
+
+  // CHECK:  [[VF1:%.+]] = load <4 x float>, <4 x float>* %vf1.addr, align 16
+  // CHECK-NEXT: call <4 x float> @llvm.cos.v4f32(<4 x float> [[VF1]])
+  vf2 = __builtin_elementwise_cos(vf1);
+}
+
 void test_builtin_elementwise_floor(float 

  1   2   >