[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-05-04 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk edited 
https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-05-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From c1aa5c649c052c230cc76d073186ad8fdd14723f Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Sun, 4 May 2025 02:13:29 +0300
Subject: [PATCH] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst   |  3 +
 .../include/clang/Basic/AttributeCommonInfo.h | 11 ++-
 clang/include/clang/Basic/Attributes.h|  7 +-
 clang/include/clang/Basic/CMakeLists.txt  |  6 ++
 .../clang/Basic/DiagnosticCommonKinds.td  |  8 ++
 .../include/clang/Basic/SimpleTypoCorrector.h | 31 +++
 clang/lib/AST/CommentSema.cpp | 90 ++-
 clang/lib/Basic/Attributes.cpp| 58 ++--
 clang/lib/Basic/CMakeLists.txt|  1 +
 clang/lib/Basic/SimpleTypoCorrector.cpp   | 47 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 38 ++--
 clang/test/CXX/module/module.interface/p3.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c|  2 +-
 clang/test/Parser/cxx0x-attributes.cpp|  6 +-
 clang/test/Sema/unknown-attributes.c  | 27 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 30 +++
 clang/utils/TableGen/TableGen.cpp |  6 ++
 clang/utils/TableGen/TableGenBackends.h   |  2 +
 18 files changed, 287 insertions(+), 88 deletions(-)
 create mode 100644 clang/include/clang/Basic/SimpleTypoCorrector.h
 create mode 100644 clang/lib/Basic/SimpleTypoCorrector.cpp
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4bd9d904e1ea9..3664eec769aff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,9 @@ related warnings within the method body.
 - Clang now disallows the use of attributes applied before an
   ``extern template`` declaration (#GH79893).
 
+- Clang now diagnoses unknown attribute namespaces and
+  provides typo correction for unrecognized namespace and attribute names 
(#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 4af5a8fd1852c..45f3d241cca32 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -16,11 +16,12 @@
 
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
-
 namespace clang {
 
 class ASTRecordWriter;
 class IdentifierInfo;
+class LangOptions;
+class TargetInfo;
 
 class AttributeCommonInfo {
 public:
@@ -67,7 +68,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, UNKNOWN };
   enum class AttrArgsInfo {
 None,
 Optional,
@@ -234,6 +235,12 @@ class AttributeCommonInfo {
 return SyntaxUsed == AS_ContextSensitiveKeyword;
   }
 
+  bool isUnknownScopeName() const;
+
+  llvm::StringRef correctScopeTypo() const;
+  llvm::StringRef correctAttributeTypo(const TargetInfo &Target,
+   const LangOptions &LangOpts) const;
+
   unsigned getAttributeSpellingListIndex() const {
 assert((isAttributeSpellingListCalculated() || AttrName) &&
"Spelling cannot be found");
diff --git a/clang/include/clang/Basic/Attributes.h 
b/clang/include/clang/Basic/Attributes.h
index 99bb668fe32d0..e17845f5c7d39 100644
--- a/clang/include/clang/Basic/Attributes.h
+++ b/clang/include/clang/Basic/Attributes.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_BASIC_ATTRIBUTES_H
 
 #include "clang/Basic/AttributeCommonInfo.h"
-
+#include "llvm/ADT/StringRef.h"
 namespace clang {
 
 class IdentifierInfo;
@@ -19,6 +19,11 @@ class TargetInfo;
 
 /// Return the version number associated with the attribute if we
 /// recognize and implement the attribute specified by the given information.
+int hasAttribute(AttributeCommonInfo::Syntax Syntax,
+ const IdentifierInfo *Scope, llvm::StringRef AttrName,
+ const TargetInfo &Target, const LangOptions &LangOpts,
+ bool CheckPlugins);
+
 int hasAttribute(AttributeCommonInfo::Syntax Syntax,
  const IdentifierInfo *Scope, const IdentifierInfo *Attr,
  const TargetInfo &Target, const LangOptions &LangOpts);
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 265ea1fc06494..d25af5d8cf73a 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -79,6 +79,12 @@ clang_tablegen(CXX11AttributeInfo.inc 
-gen-cxx11-attribute-info
   TARGET CXX11AttributeInfo
   )
 
+clang_tablegen(AttributeSpellingList.inc -gen-attribute-spelling-list
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../
+  SOURCE A

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-05-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk edited 
https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-05-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From 9bb85586f40f659a8bff414511bed9592083efbd Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Sun, 4 May 2025 01:13:20 +0300
Subject: [PATCH 1/2] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst   |  3 +
 .../include/clang/Basic/AttributeCommonInfo.h | 11 ++-
 clang/include/clang/Basic/Attributes.h|  7 +-
 clang/include/clang/Basic/CMakeLists.txt  |  6 ++
 .../clang/Basic/DiagnosticCommonKinds.td  |  8 ++
 .../include/clang/Basic/SimpleTypoCorrector.h | 31 +++
 clang/lib/AST/CommentSema.cpp | 90 ++-
 clang/lib/Basic/Attributes.cpp| 58 ++--
 clang/lib/Basic/CMakeLists.txt|  1 +
 clang/lib/Basic/SimpleTypoCorrector.cpp   | 47 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 38 ++--
 clang/test/CXX/module/module.interface/p3.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c|  2 +-
 clang/test/Parser/cxx0x-attributes.cpp|  6 +-
 clang/test/Sema/unknown-attributes.c  | 27 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 32 +++
 clang/utils/TableGen/TableGen.cpp |  6 ++
 clang/utils/TableGen/TableGenBackends.h   |  2 +
 18 files changed, 289 insertions(+), 88 deletions(-)
 create mode 100644 clang/include/clang/Basic/SimpleTypoCorrector.h
 create mode 100644 clang/lib/Basic/SimpleTypoCorrector.cpp
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc68bb8b70b3d..7679adb3c022b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -333,6 +333,9 @@ related warnings within the method body.
 - Clang now disallows the use of attributes applied before an
   ``extern template`` declaration (#GH79893).
 
+- Clang now diagnoses unknown attribute namespaces and
+  provides typo correction for unrecognized namespace and attribute names 
(#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 4af5a8fd1852c..45f3d241cca32 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -16,11 +16,12 @@
 
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
-
 namespace clang {
 
 class ASTRecordWriter;
 class IdentifierInfo;
+class LangOptions;
+class TargetInfo;
 
 class AttributeCommonInfo {
 public:
@@ -67,7 +68,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, UNKNOWN };
   enum class AttrArgsInfo {
 None,
 Optional,
@@ -234,6 +235,12 @@ class AttributeCommonInfo {
 return SyntaxUsed == AS_ContextSensitiveKeyword;
   }
 
+  bool isUnknownScopeName() const;
+
+  llvm::StringRef correctScopeTypo() const;
+  llvm::StringRef correctAttributeTypo(const TargetInfo &Target,
+   const LangOptions &LangOpts) const;
+
   unsigned getAttributeSpellingListIndex() const {
 assert((isAttributeSpellingListCalculated() || AttrName) &&
"Spelling cannot be found");
diff --git a/clang/include/clang/Basic/Attributes.h 
b/clang/include/clang/Basic/Attributes.h
index 99bb668fe32d0..e17845f5c7d39 100644
--- a/clang/include/clang/Basic/Attributes.h
+++ b/clang/include/clang/Basic/Attributes.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_BASIC_ATTRIBUTES_H
 
 #include "clang/Basic/AttributeCommonInfo.h"
-
+#include "llvm/ADT/StringRef.h"
 namespace clang {
 
 class IdentifierInfo;
@@ -19,6 +19,11 @@ class TargetInfo;
 
 /// Return the version number associated with the attribute if we
 /// recognize and implement the attribute specified by the given information.
+int hasAttribute(AttributeCommonInfo::Syntax Syntax,
+ const IdentifierInfo *Scope, llvm::StringRef AttrName,
+ const TargetInfo &Target, const LangOptions &LangOpts,
+ bool CheckPlugins);
+
 int hasAttribute(AttributeCommonInfo::Syntax Syntax,
  const IdentifierInfo *Scope, const IdentifierInfo *Attr,
  const TargetInfo &Target, const LangOptions &LangOpts);
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 265ea1fc06494..d25af5d8cf73a 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -79,6 +79,12 @@ clang_tablegen(CXX11AttributeInfo.inc 
-gen-cxx11-attribute-info
   TARGET CXX11AttributeInfo
   )
 
+clang_tablegen(AttributeSpellingList.inc -gen-attribute-spelling-list
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../
+  SOUR

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-05-03 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From 9bb85586f40f659a8bff414511bed9592083efbd Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk 
Date: Sun, 4 May 2025 01:13:20 +0300
Subject: [PATCH] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst   |  3 +
 .../include/clang/Basic/AttributeCommonInfo.h | 11 ++-
 clang/include/clang/Basic/Attributes.h|  7 +-
 clang/include/clang/Basic/CMakeLists.txt  |  6 ++
 .../clang/Basic/DiagnosticCommonKinds.td  |  8 ++
 .../include/clang/Basic/SimpleTypoCorrector.h | 31 +++
 clang/lib/AST/CommentSema.cpp | 90 ++-
 clang/lib/Basic/Attributes.cpp| 58 ++--
 clang/lib/Basic/CMakeLists.txt|  1 +
 clang/lib/Basic/SimpleTypoCorrector.cpp   | 47 ++
 clang/lib/Sema/SemaDeclAttr.cpp   | 38 ++--
 clang/test/CXX/module/module.interface/p3.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c|  2 +-
 clang/test/Parser/cxx0x-attributes.cpp|  6 +-
 clang/test/Sema/unknown-attributes.c  | 27 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 32 +++
 clang/utils/TableGen/TableGen.cpp |  6 ++
 clang/utils/TableGen/TableGenBackends.h   |  2 +
 18 files changed, 289 insertions(+), 88 deletions(-)
 create mode 100644 clang/include/clang/Basic/SimpleTypoCorrector.h
 create mode 100644 clang/lib/Basic/SimpleTypoCorrector.cpp
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc68bb8b70b3d..7679adb3c022b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -333,6 +333,9 @@ related warnings within the method body.
 - Clang now disallows the use of attributes applied before an
   ``extern template`` declaration (#GH79893).
 
+- Clang now diagnoses unknown attribute namespaces and
+  provides typo correction for unrecognized namespace and attribute names 
(#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 4af5a8fd1852c..45f3d241cca32 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -16,11 +16,12 @@
 
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TokenKinds.h"
-
 namespace clang {
 
 class ASTRecordWriter;
 class IdentifierInfo;
+class LangOptions;
+class TargetInfo;
 
 class AttributeCommonInfo {
 public:
@@ -67,7 +68,7 @@ class AttributeCommonInfo {
 IgnoredAttribute,
 UnknownAttribute,
   };
-  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV };
+  enum class Scope { NONE, CLANG, GNU, MSVC, OMP, HLSL, GSL, RISCV, UNKNOWN };
   enum class AttrArgsInfo {
 None,
 Optional,
@@ -234,6 +235,12 @@ class AttributeCommonInfo {
 return SyntaxUsed == AS_ContextSensitiveKeyword;
   }
 
+  bool isUnknownScopeName() const;
+
+  llvm::StringRef correctScopeTypo() const;
+  llvm::StringRef correctAttributeTypo(const TargetInfo &Target,
+   const LangOptions &LangOpts) const;
+
   unsigned getAttributeSpellingListIndex() const {
 assert((isAttributeSpellingListCalculated() || AttrName) &&
"Spelling cannot be found");
diff --git a/clang/include/clang/Basic/Attributes.h 
b/clang/include/clang/Basic/Attributes.h
index 99bb668fe32d0..e17845f5c7d39 100644
--- a/clang/include/clang/Basic/Attributes.h
+++ b/clang/include/clang/Basic/Attributes.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_BASIC_ATTRIBUTES_H
 
 #include "clang/Basic/AttributeCommonInfo.h"
-
+#include "llvm/ADT/StringRef.h"
 namespace clang {
 
 class IdentifierInfo;
@@ -19,6 +19,11 @@ class TargetInfo;
 
 /// Return the version number associated with the attribute if we
 /// recognize and implement the attribute specified by the given information.
+int hasAttribute(AttributeCommonInfo::Syntax Syntax,
+ const IdentifierInfo *Scope, llvm::StringRef AttrName,
+ const TargetInfo &Target, const LangOptions &LangOpts,
+ bool CheckPlugins);
+
 int hasAttribute(AttributeCommonInfo::Syntax Syntax,
  const IdentifierInfo *Scope, const IdentifierInfo *Attr,
  const TargetInfo &Target, const LangOptions &LangOpts);
diff --git a/clang/include/clang/Basic/CMakeLists.txt 
b/clang/include/clang/Basic/CMakeLists.txt
index 265ea1fc06494..d25af5d8cf73a 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -79,6 +79,12 @@ clang_tablegen(CXX11AttributeInfo.inc 
-gen-cxx11-attribute-info
   TARGET CXX11AttributeInfo
   )
 
+clang_tablegen(AttributeSpellingList.inc -gen-attribute-spelling-list
+  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../
+  SOURCE A

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-04-29 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> @erichkeane @AaronBallman @cor3ntin, just checking if there are any updates 
> on this, as the `Clang 20` release was landed.

Erich and I discussed this more offline and our thinking is:

* It's useful for `-Wunknown-attributes` to print the attribute namespace
* We think there should be typo correction for `-Wunknown-attributes`, for both 
the attribute namespace and the attribute name
* We're both struggling to find "warn about unknown attribute namespaces" to be 
motivating because we don't think there are a lot of unknown attribute 
namespaces in the wild. Does anyone know of a static analysis tool which 
supplies custom attributes? Or is this currently limited to just plugin 
attributes in practice? If plugin attributes, we weakly think it might be worth 
holding off on a separate warning. If there are static analysis tools with 
custom attributes, then we think that diagnostic is a bit more motivated.


https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-04-28 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@erichkeane @AaronBallman @cor3ntin, just checking if there are any updates on 
this, as the `Clang 20` release was landed.



https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-27 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> Ultimately we want
> 
> 1. I know all of these attributes, don't tell me about them
> 
> 2. I know all of these attribute namespaces, don't tell me about them - 
> which this patch is doing
> 
> 3. Have a way to disable unknown attributes warnings for all unknown 
> namespaces - which this patch is doing by introducing a separate flag
> 
> 
> I sort of question the last bullet point (the original issue), as it's a bit 
> of a nuclear option. But maybe that's fine. Then there is the question of 
> whether 1. and 2. should have separate interfaces.
> 
> I will also point out that `-Wunknown-attribute-namespaces=foo` is a very 
> weird way to spell "I know about `foo`, don't warn on it" - and I am 
> concerned about discoverability.

Yeah, I was thinking about the converse: 
`-Wno-unknown-attribute-namespaces=foo` seems almost like it's how we'd want to 
spell it, but that's pretty novel.

> And again, I apologize I did not see this patch sooner @a-tarasyuk. What do 
> people think about landing it early in the Clang 21 cycle, in case we find a 
> better long term interface in the next few months?

I think it makes sense to not land this for Clang 20 so we can get the 
interface right the first time.

Let's see if we have some agreement on where we're at.

1) We want `-Wunknown-attributes` to print attribute namespace names, but 
that's a separate PR from this one.
2) We have a user who wants a way to silence diagnostics about all unknown 
attributes if the attribute namespace itself is unknown.
3) We don't necessarily need to let the user specify a set of which unknown 
attribute namespaces to warn about. We could wait on this until there's user 
demand with a real world example.
4) Given that unknown attribute namespaces are uncommon, nothing needs to be 
done in a rush, we may even decide we don't need this option at all despite (2).

Does that seem like an accurate summary?

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-27 Thread via cfe-commits

cor3ntin wrote:

Ultimately we want

1.  I know all of these attributes, don't tell me about them
2.  I know all of these attribute namespaces, don't tell me about them - which 
this patch is doing
3.   Have a way to disable unknown attributes warnings for all unknown 
namespaces - which this patch is doing by introducing a separate flag

I sort of question the last bullet point (the original issue), as it's a bit of 
a nuclear option. But maybe that's fine.
Then there is the question of whether 1. and 2. should have separate interfaces.

I will also point out that `-Wunknown-attribute-namespaces=foo` is a very weird 
way to spell "I know about `foo`, don't warn on it" - and I am concerned about 
discoverability.


And again, I apologize I did not see this patch sooner @a-tarasyuk.
What do people think about landing it early in the Clang 21 cycle, in case we 
find a better long term interface in the next few months?


https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Erich Keane via cfe-commits

erichkeane wrote:

>For example, we know about the gnu namespace, but there are a ton of 
>attributes GCC supports but we do not.

Sure, but we've never needed/wanted that before for general attributes, right?  
I am seeing THAT as particularly novel for this patch.  I would be open to 
reviewing that, but don't see it as necessary for this patch.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > > > That's how this already works in this patch:
> > > > AH! I missed that this was doing that.  Awesome!  Though I think the 
> > > > 'no' flag is the one that makes sense in a "turn it on for all BUT 
> > > > these". The flag as typed there isn't particularly useful (that is, 
> > > > ONLY warn me for the ones that I know about).
> > > 
> > > 
> > > > I think what Corentin is asking for is a similar (follow-up?) feature 
> > > > that allows you to say "warn me about unknown attributes, but not of 
> > > > unknown attributes." that can take attributes with or without a 
> > > > namespace.
> > > 
> > > 
> > > I'm not hearing a difference?
> > 
> > 
> > Wow. My fingers are obviously not listening to my brain very well. :-D
> > I mean "warn me about unknown attribute, but not these particular unknown 
> > attributes." e.g., (fake warning group name)
> > ```
> > // -Wwarn-about-unknown-attributes-except-these=foo,bar::baz
> > [[foo, bar::baz, quux]] int x; // warning: unknown attribute 'quux'
> > ```
> 
> Ah, hrm. I see much less value in that. How likely is it that you have an 
> attribute in a 'known' namespace that is 'unknown' but valid? 

For example, we know about the `gnu` namespace, but there are a ton of 
attributes GCC supports but we do not.


https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Erich Keane via cfe-commits

erichkeane wrote:

> > > That's how this already works in this patch:
> > > AH! I missed that this was doing that.  Awesome!  Though I think the 'no' 
> > > flag is the one that makes sense in a "turn it on for all BUT these". The 
> > > flag as typed there isn't particularly useful (that is, ONLY warn me for 
> > > the ones that I know about).
> > 
> > 
> > > I think what Corentin is asking for is a similar (follow-up?) feature 
> > > that allows you to say "warn me about unknown attributes, but not of 
> > > unknown attributes." that can take attributes with or without a namespace.
> > 
> > 
> > I'm not hearing a difference?
> 
> Wow. My fingers are obviously not listening to my brain very well. :-D
> 
> I mean "warn me about unknown attribute, but not these particular unknown 
> attributes." e.g., (fake warning group name)
> 
> ```
> // -Wwarn-about-unknown-attributes-except-these=foo,bar::baz
> [[foo, bar::baz, quux]] int x; // warning: unknown attribute 'quux'
> ```

Ah, hrm.  I see much less value in that.  How likely is it that you have an 
attribute in a 'known' namespace that is 'unknown' but valid?  I thought the 
whole point of namespaces was that this is NOT particularly useful?

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > That's how this already works in this patch:
> > AH! I missed that this was doing that.  Awesome!  Though I think the 'no' 
> > flag is the one that makes sense in a "turn it on for all BUT these". The 
> > flag as typed there isn't particularly useful (that is, ONLY warn me for 
> > the ones that I know about).
> 
> > I think what Corentin is asking for is a similar (follow-up?) feature that 
> > allows you to say "warn me about unknown attributes, but not of unknown 
> > attributes." that can take attributes with or without a namespace.
> 
> I'm not hearing a difference?

Wow. My fingers are obviously not listening to my brain very well. :-D

I mean "warn me about unknown attribute, but not these particular unknown 
attributes." e.g., (fake warning group name)
```
// -Wwarn-about-unknown-attributes-except-these=foo,bar::baz
[[foo, bar::baz, quux]] int x; // warning: unknown attribute 'quux'
```

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Erich Keane via cfe-commits

erichkeane wrote:

>That's how this already works in this patch:
AH! I missed that this was doing that.  Awesome!  Though I think the 'no' flag 
is the one that makes sense in a "turn it on for all BUT these". The flag as 
typed there isn't particularly useful (that is, ONLY warn me for the ones that 
I know about).

>I think what Corentin is asking for is a similar (follow-up?) feature that 
>allows you to say "warn me about unknown attributes, but not of unknown 
>attributes." that can take attributes with or without a namespace.

I'm not hearing a difference?

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > Thanks for this patch.
> > Sorry I did not see this sooner.
> > I am not convinced this the best way to resolve #120875 - and I suspect in 
> > practice it would be a bit difficult to use/be under used.
> 
> I'm not convinced here? I think a flag that says "warn me about unknown 
> namespaces" is particularly useful, but the effect of "don't warn me about 
> unknown namespaces, but warn me about attributes in known namespaces" _IS_ 
> also particularly useful. (that is, if you don't know the namespace, shush, 
> else tell me about it).

+1

> > I think the general desire is for users to have a way (maybe a file) where 
> > they can list all the attributes they want the implementation to ignore 
> > when unknown (with their namespaces).
> 
> If anything, a list on a command line as an extension to this (that is, don't 
> warn me about THIS LIST of unknown namespaces) would be incredibly useful, 
> something like: 
> `-Wno-unknown-namespace-attributes=my_static_analysis_tool,my_annotation`. 
> But I think this is independently useful without it .

That's how this already works in this patch:
```
// RUN: %clang_cc1 -fsyntax-only -Wunknown-attribute-namespaces=foo,bar 
-std=c23 \
// RUN:   %s 2>&1 | FileCheck %s --check-prefixes=CHECK_UNKNOWN_ATTR_NS
```
I think what Corentin is asking for is a similar (follow-up?) feature that 
allows you to say "warn me about unknown attributes, but not  of unknown attributes." that can take attributes with or without a 
namespace.

Btw, I just realized we only have tests for 
`-Wunknown-attribute-namespaces=foo,bar` but not for 
`-Wno-unknown-attribute-namespaces=foo,bar`; we should test that behavior too.

>> I think we should definitely display the namespace name in the current 
>> diagnostic

I'm in total support of that, though not as part of this PR.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-24 Thread Erich Keane via cfe-commits

erichkeane wrote:

> Thanks for this patch.
> 
> Sorry I did not see this sooner.
> 
> I am not convinced this the best way to resolve #120875 - and I suspect in 
> practice it would be a bit difficult to use/be under used. 

I'm not convinced here?  I think a flag that says "warn me about unknown 
namespaces" is particularly useful, but the effect of "don't warn me about 
unknown namespaces, but warn me about attributes in known namespaces" _IS_ also 
particularly useful.  (that is, if you don't know the namespace, shush, else 
tell me about it).

>I think the general desire is for users to have a way (maybe a file) where 
>they can list all the attributes they want the implementation to ignore when 
>unknown (with their namespaces). 

If anything, a list on a command line as an extension to this (that is, don't 
warn me about THIS LIST of unknown namespaces) would be incredibly useful, 
something like: 
`-Wno-unknown-namespace-attributes=my_static_analysis_tool,my_annotation`.  But 
I think this is independently useful without it .

>Additionally this should be used to typo correct. I am not convinced that the 
>current subset that just allows a list of namespace hidden in a warning flag 
>is sufficient / worth it.

THAT is the downside unfortunately to our diagnostics system in general, and 
I'm particularly upset in this case that we don't have a way of differentiating 
between 'typo' and 'intentionally ignored.  Which is why the flag you propose I 
believe is a REALLY good idea, but I'm hesitent to make it required in this 
patch.
> 
> I think we should definitely display the namespace name in the current 
> diagnostic, but for the opt-out mechanism, i think we should have a better 
> sense of a solution that covers all the use cases and then implement that.
> 
> Note that I haven't chatted to @AaronBallman and @erichkeane yet, but I think 
> that's worth discussing before proceeding.
> 
> P.S: Please offer a description in your non-trivial changes, explaining your 
> design choices and so forth. thanks a lot



https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread via cfe-commits

cor3ntin wrote:

Thanks for this patch.

Sorry I did not see this sooner.

I am not convinced this the best way to resolve #120875 - and I suspect in 
practice it would be a bit difficult to use/be under used.
I think the general desire is for users to have a way (maybe a file) where they 
can list all the attributes they want the implementation to ignore when unknown 
(with their namespaces).
Additionally this should be used to typo correct.
I am not convinced that the current subset that just allows a list of namespace 
hidden in a warning flag is sufficient / worth it.

-- 
I think we should definitely display the namespace name in the current 
diagnostic, but for the opt-out mechanism, i think we should have a better 
sense of a solution that covers all the use cases and then implement that.

Note that I haven't chatted to @AaronBallman and @erichkeane yet, but I think 
that's worth discussing before proceeding.


-- 

P.S: Please offer a description in your non-trivial changes, explaining your 
design choices and so forth. thanks a lot


https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread Oleksandr T. via cfe-commits


@@ -822,6 +822,7 @@ def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
 def NSConsumedMismatch : DiagGroup<"nsconsumed-mismatch">;
 def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">;
 
+def UnknownAttributeNamespaces : DiagGroup<"unknown-attribute-namespaces">;
 def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">;
 def UnknownAttributes : DiagGroup<"unknown-attributes">;

a-tarasyuk wrote:

These test cases are definitely valuable, thanks! I've added them.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/9] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/8] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread Aaron Ballman via cfe-commits


@@ -822,6 +822,7 @@ def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
 def NSConsumedMismatch : DiagGroup<"nsconsumed-mismatch">;
 def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">;
 
+def UnknownAttributeNamespaces : DiagGroup<"unknown-attribute-namespaces">;
 def IndependentClassAttribute : DiagGroup<"IndependentClass-attribute">;
 def UnknownAttributes : DiagGroup<"unknown-attributes">;

AaronBallman wrote:

I think the warning group makes sense to add to `UnknownAttributes` because I 
think the behavior we want is:
```
// -Wunknow-attributes; tell me about all kinds of unknown attributes
[[frob::foo]][[gnu::fd_arg]] void func();
// warning: unknown attribute namespace 'frob'; attribute 'frob::foo' ignored 
[-Wuknown-attribute-namespaces]
// warning: unknown attribute 'fd_arg' ignored [-Wunknown-attributes]

// -Wunknown-attributes -Wno-unknown-attribute-namespaces; only tell me about 
unknown attributes in a known attribute namespace
[[frob::foo]][[gnu::fd_arg]] void func();
// warning: unknown attribute 'foo' ignored [-Wuknown-attributes]

// -Wno-unknown-attributes -Wunknown-attribute-namespaces; only tell me about 
unknown attribute namespaces
[[frob::foo]][[gnu::fd_arg]] void func();
// warning: unknown attribute namespace 'frob'; attribute 'frob::foo' ignored 
[-Wuknown-attribute-namespaces]

// -Wno-unknown-attributes; don't tell me about unknown attributes at all
[[frob::foo]][[gnu::fd_arg]] void func(); // no warnings
```
WDYT? If you agree, this would be a pretty useful test case to add.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread Aaron Ballman via cfe-commits


@@ -606,6 +606,8 @@ Attribute Changes in Clang
 
 - Clang now disallows the use of attributes after the namespace name. 
(#GH121407)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).

AaronBallman wrote:

This is incorrect; it adds a new diagnostic group rather than a pedantic 
warning.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-23 Thread Oleksandr T. via cfe-commits


@@ -166,7 +166,8 @@ getScopeFromNormalizedScopeName(StringRef ScopeName) {
   .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
   .Case("msvc", AttributeCommonInfo::Scope::MSVC)
   .Case("omp", AttributeCommonInfo::Scope::OMP)
-  .Case("riscv", AttributeCommonInfo::Scope::RISCV);
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)
+  .Default(AttributeCommonInfo::Scope::NONE);

a-tarasyuk wrote:

I added `UNKNOWN` kind as the default case

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Oleksandr T. via cfe-commits


@@ -1115,6 +1115,11 @@ defm cx_fortran_rules: BoolOptionWithoutMarshalling<"f", 
"cx-fortran-rules",
   NegFlag>;
 
+def Wunknown_attribute_namespace_EQ : CommaJoined<["-"], 
"Wunknown-attribute-namespace=">,
+  Group, Flags<[HelpHidden]>, Visibility<[ClangOption, 
CC1Option]>,
+  HelpText<"Specify a comma-separated list of allowed unknown attribute 
namespaces">,

a-tarasyuk wrote:

@AaronBallman thanks for the feedback. There is a test that disallows such 
options from appearing in the help - should it be changed?

https://github.com/llvm/llvm-project/blob/ac94fade6075fec89eb29c7dedf01ef59601e61d/clang/test/Driver/immediate-options.c#L6

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/5] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Aaron Ballman via cfe-commits


@@ -1115,6 +1115,11 @@ defm cx_fortran_rules: BoolOptionWithoutMarshalling<"f", 
"cx-fortran-rules",
   NegFlag>;
 
+def Wunknown_attribute_namespace_EQ : CommaJoined<["-"], 
"Wunknown-attribute-namespace=">,
+  Group, Flags<[HelpHidden]>, Visibility<[ClangOption, 
CC1Option]>,
+  HelpText<"Specify a comma-separated list of allowed unknown attribute 
namespaces">,

AaronBallman wrote:

It's a little bit odd that we have help text for something with the 
`HelpHidden` flag. Can probably remove the `HelpText`.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Aaron Ballman via cfe-commits


@@ -166,7 +166,8 @@ getScopeFromNormalizedScopeName(StringRef ScopeName) {
   .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
   .Case("msvc", AttributeCommonInfo::Scope::MSVC)
   .Case("omp", AttributeCommonInfo::Scope::OMP)
-  .Case("riscv", AttributeCommonInfo::Scope::RISCV);
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)
+  .Default(AttributeCommonInfo::Scope::NONE);

AaronBallman wrote:

Won't it be surprising that `""` and `"wobble"` will both come back as `NONE`? 
I would have expected the latter to return something like "Unknown" so it's 
distinguished from no scope name.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunknown-attribute-namespace=foo,bar 
-std=c23 -verify %s

AaronBallman wrote:

Can you also add a `RUN` line with `-x c++` to show we get the same behavior in 
C and C++?

Also, we may want to consider adding a `FileCheck` test (instead of a `-verify` 
test) so that we can validate the correct warning group is emitted after the 
diagnostic. e.g., unknown namespaces should get you 
`[-Wunknown-attribute-namespace]` while unknown attributes in a known namespace 
should still get `[-Wunknown-attributes]`

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Aaron Ballman via cfe-commits


@@ -822,8 +822,9 @@ def NSobjectAttribute : DiagGroup<"NSObject-attribute">;
 def NSConsumedMismatch : DiagGroup<"nsconsumed-mismatch">;
 def NSReturnsMismatch : DiagGroup<"nsreturns-mismatch">;
 
+def UnknownAttributeNamespace : DiagGroup<"unknown-attribute-namespace">;

AaronBallman wrote:

Do we want to have a slightly different diagnostic wording for this case? e.g., 
`unknown attribute namespace '%0'; attribute '%0::%1' ignored`?

That way it's more clear that we don't know any attributes from that namespace?

Also, given that it's `-Wunknown-attributes` (plural) should this be 
`-Wunknown-attribute-namespaces`? I don't have a strong opinion, just caught my 
attention that one was plural and the other wasn't.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-22 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/4] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-14 Thread Aaron Ballman via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

AaronBallman wrote:

Yes, we'd definitely want to support comma-delimited lists of these. I'm on the 
fence about the wording suggestion but not strongly opposed. I think the 
hardest part about my suggestion is that warning flags with `=` in them are 
poorly supported, so we'd need more tablegen machinery I think: 
https://github.com/llvm/llvm-project/blob/1594413d5edf6a47d4100cb6a2bc613cfbb92beb/clang/include/clang/Basic/DiagnosticGroups.td#L1036

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-13 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

>Do we want to support a grouping like -Wno-unknown-attribute-namespace=frobble 
>where leaving off the = means we silence all unknown attribute namespaces?

I think that is a NEAT feature, but I fear one that is a lot of work for 
something that basically no one will figure out how to use (since people 
discover -Wno flags from our diagnostics), and thus no one will. If we DO 
something like that, I would want to see if we could do a note attached to it 
of:
`to disable this diagnostic for this namespace, use 
`-Wno-unknown-attribute-namespace=frobble`.  ALSO, we should support 
comma-delimited.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-13 Thread Aaron Ballman via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

AaronBallman wrote:

> Curiously, and after I sent that, I realized why WE of all compilers SHOULD 
> warn here, even if others don't. Clang supports/recognizes the prefixes of 
> all of the major compilers, which drastically increases the chance that an 
> unrecognized one is a typo rather than an intentional difference.

+1; the current behavior of warning even when we don't know the namespace is 
entirely intentional for exactly that reason.

I think it's reasonable for us to have a new warning group so if there is an 
attribute namespace heavily used in a project, the developer can disable just 
the unknown namespace ones while still getting other diagnostics about unknown 
attributes. However, what should the user do when they want to silence 
diagnostics about `[[frobble::gobble]]` but not silence diagnostics about 
`[[edg::whatever]]`? Do we want to support a grouping like 
`-Wno-unknown-attribute-namespace=frobble` where leaving off the `=` means we 
silence all unknown attribute namespaces?

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

Curiously, and after I sent that, I realized why _WE_ of all compilers SHOULD 
warn here, even if others don't.  Clang supports/recognizes the prefixes of all 
of the major compilers, which drastically increases the chance that an 
unrecognized one is a typo rather than an intentional difference.  

It would be justifiable to have a 'list' of ones that we don't recognize, but 
acknowledge that is hidden under that extension warning, but we SHOULD be doing 
`gcc` and `gmu` and `clagn` the same severity/applicability as if you 
misspelled it as `caries_dependency`.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

I see that, though disagree somewhat.  I see value in it being a separate 
GROUP, but it should still be a warning.  The intent of attributes THEMSELVES 
is to be ignorable without #ifdef-hell, so the criticisms against the prefix is 
the same here.

Though note: the intent of the prefixes was NOT actually to avoid #ifdef-hell 
(at least in C++, though it might have been used as side-justification in 
WG14).  The point was to ensure that the 'global' namespace was reserved for 
the standard attributes, and provide an extension point for implementers.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Oleksandr T. via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

a-tarasyuk wrote:

No, I didn't. Should we address the following concern (maybe only for `c23`) by 
using a new group with `extension` handling?

> With --std=c23, when using attributes with an arbitrary attribute-prefix, 
> Clang raises the warning -Wunknown-attributes
The whole point of attribute-prefixs is to be able to use attributes for 
multiple compilers without a #ifdef-hell. Thus, there is no reason for this 
warning to be raised. And if a warning has to be raised, it should be a 
different one (perhaps -Wunknown-attribute-prefix) such that it can selectively 
be disabled (since -Wunknown-attributes is useful in case of misspelled 
attributes in general).

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

> From my understanding of the issue, an _unknown_ attr scope shouldn't result 
> in a warning by default. It should only be handled when a specific flag is 
> enabled or in pedantic mode. For that reason, I added an extension warning., 
> or is this not applicable in this case?

That is not my understanding.  For example, we'd want to warn/identify someone 
typing `gcc` instead of `gnu`, or `calng` instead of `clang`, the same way we 
want to identify `nodiscard` vs `no_discard`.  

Did you see a discussion about this somewhere else?  I'd be curious to see what 
@AaronBallman has to say about this when he returns from his break.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Oleksandr T. via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

a-tarasyuk wrote:

>From my understanding of the issue, an _unknown_ attr scope shouldn't result 
>in a warning by default. It should only be handled when a specific flag is 
>enabled or in pedantic mode. For that reason, I added an extension warning., 
>or is this not applicable in this case?



https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

I would expect this to be a normal warning.  The difference between 
`clang::Unknown` and `Unknown::UnknownAttr` are the same severity/warning 
type/etc.  A different MESSAGE is sensible, and a different warning GROUP is 
equally as sensible, but one being a warning and the other an extension seems 
odd.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-03 Thread Erich Keane via cfe-commits


@@ -166,7 +166,8 @@ getScopeFromNormalizedScopeName(StringRef ScopeName) {
   .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
   .Case("msvc", AttributeCommonInfo::Scope::MSVC)
   .Case("omp", AttributeCommonInfo::Scope::OMP)
-  .Case("riscv", AttributeCommonInfo::Scope::RISCV);
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)

erichkeane wrote:

Ah, that appears to be the correct list, yes, thank you!

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Oleksandr T. via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

a-tarasyuk wrote:

@erichkeane thanks for the feedback. should cases like `unknown:a` not trigger 
warnings, even in _pedantic_ mode?







https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Oleksandr T. via cfe-commits


@@ -166,7 +166,8 @@ getScopeFromNormalizedScopeName(StringRef ScopeName) {
   .Case("hlsl", AttributeCommonInfo::Scope::HLSL)
   .Case("msvc", AttributeCommonInfo::Scope::MSVC)
   .Case("omp", AttributeCommonInfo::Scope::OMP)
-  .Case("riscv", AttributeCommonInfo::Scope::RISCV);
+  .Case("riscv", AttributeCommonInfo::Scope::RISCV)

a-tarasyuk wrote:

@erichkeane is this a correct list of supported scopes?



https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/3] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Erich Keane via cfe-commits


@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}

erichkeane wrote:

This shows the exact problem here that I have above.  We KNOW 'clang' (in fact, 
we OWN it).  We should diagnose this as an unknown attribute, not as an unknown 
namespace.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Erich Keane via cfe-commits


@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;

erichkeane wrote:

the text here should be different, we need to say something about how we don't 
know it because we don't support the whole namespace.

Also, I don't think this makes sense as an extension warning, we should 
diagnose unknown namespace, but it isn't any different than unknown attribute 
in severity.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-01-02 Thread Erich Keane via cfe-commits


@@ -6548,7 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
-   : (unsigned)diag::warn_unknown_attribute_ignored)
+   : AL.getScopeName() ? (unsigned)diag::ext_unknown_attribute_ignored

erichkeane wrote:

This part isn't right, this changes our `clang::Baz` warning to an extension, 
when we only want to do it when we don't know what the namespace is.  We likely 
need to do some tablegen work to show the list of namespaces that we support, 
and issue the diagnostic there.

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2024-12-23 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

@namandixit it is possible. I'm not confident about the new option., 
@AaronBallman @erichkeane  - should _unknown namespaced attributes_ be 
separated by the new option?

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2024-12-23 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/120925

>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH 1/2] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expec

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2024-12-22 Thread Naman Dixit via cfe-commits

namandixit wrote:

Hi, is it possible to add a separate warning for unknown prefixes (as requested 
in the issue)? Enabling `-Wpedantic` is usually considered a best practice, and 
mixing useful warnings (unknown attribute) and less useful ones (unknown 
attribute prefix) will only drive people to either disable the pedantic mode or 
disable the warning altogether (which is something that can already be done).

https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2024-12-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 44514316bd5ef656076b6baaf6bccb298d98f0ea 
bce88b1bb464438828fc177c978ad2b99957530f --extensions c,cpp -- 
clang/test/Sema/unknown-attributes.c clang/lib/Sema/SemaDeclAttr.cpp 
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
clang/test/CXX/module/module.interface/p3.cpp 
clang/test/Lexer/cxx2a-spaceship.cpp 
clang/test/OpenMP/openmp_attribute_parsing.cpp 
clang/test/Parser/c2x-attributes.c clang/test/Parser/cxx0x-attributes.cpp 
clang/test/Sema/patchable-function-entry-attr.cpp 
clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 9b1ffebe08..520508a2c9 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,9 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
-   : AL.getScopeName()
-   ? (unsigned)diag::ext_unknown_attribute_ignored
-   : (unsigned)diag::warn_unknown_attribute_ignored)
+   : AL.getScopeName() ? (unsigned)diag::ext_unknown_attribute_ignored
+   : 
(unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
   }

``




https://github.com/llvm/llvm-project/pull/120925
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2024-12-22 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #120875


---
Full diff: https://github.com/llvm/llvm-project/pull/120925.diff


12 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticCommonKinds.td (+2) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+2) 
- (modified) clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp (+2-2) 
- (modified) clang/test/CXX/module/module.interface/p3.cpp (+1-1) 
- (modified) clang/test/Lexer/cxx2a-spaceship.cpp (+1-1) 
- (modified) clang/test/OpenMP/openmp_attribute_parsing.cpp (+1-1) 
- (modified) clang/test/Parser/c2x-attributes.c (+1-1) 
- (modified) clang/test/Parser/cxx0x-attributes.cpp (+1-1) 
- (modified) clang/test/Sema/patchable-function-entry-attr.cpp (+1-1) 
- (added) clang/test/Sema/unknown-attributes.c (+10) 
- (modified) clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp (+2-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribute( // expected-warning {{unknown attribute}}
+[[some_vendor::some_attribute(
 preprocess1: ID(<)ID(=>),
 preprocess2: ID(<=)ID(>),
 preprocess3: ID(<)ID(=)ID(>),
diff --git a/clang/test/OpenMP/openmp_attribute

[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2024-12-22 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/120925

Fixes #120875


>From bce88b1bb464438828fc177c978ad2b99957530f Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 23 Dec 2024 02:35:07 +0200
Subject: [PATCH] [Clang] raise extension warning for unknown namespaced
 attributes

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Sema/SemaDeclAttr.cpp|  2 ++
 .../CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp|  4 ++--
 clang/test/CXX/module/module.interface/p3.cpp  |  2 +-
 clang/test/Lexer/cxx2a-spaceship.cpp   |  2 +-
 clang/test/OpenMP/openmp_attribute_parsing.cpp |  2 +-
 clang/test/Parser/c2x-attributes.c |  2 +-
 clang/test/Parser/cxx0x-attributes.cpp |  2 +-
 clang/test/Sema/patchable-function-entry-attr.cpp  |  2 +-
 clang/test/Sema/unknown-attributes.c   | 10 ++
 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp  |  4 ++--
 12 files changed, 26 insertions(+), 10 deletions(-)
 create mode 100644 clang/test/Sema/unknown-attributes.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..e2cf90aecf3666 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -552,6 +552,8 @@ Attribute Changes in Clang
 - Clang now permits the usage of the placement new operator in 
``[[msvc::constexpr]]``
   context outside of the std namespace. (#GH74924)
 
+- Clang now raises warnings for unknown namespaced attributes only in pedantic 
mode (#GH120875).
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index f4a155bb00bb37..85653429aa5332 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -179,6 +179,8 @@ def err_opencl_unknown_type_specifier : Error<
 
 def warn_unknown_attribute_ignored : Warning<
   "unknown attribute %0 ignored">, InGroup;
+def ext_unknown_attribute_ignored : Extension<
+  "unknown attribute %0 ignored">, InGroup;
 def warn_attribute_ignored : Warning<"%0 attribute ignored">,
   InGroup;
 def err_keyword_not_supported_on_target : Error<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index bb4d33560b93b8..9b1ffebe0804a5 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6548,6 +6548,8 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, 
const ParsedAttr &AL,
? (unsigned)diag::err_keyword_not_supported_on_target
: AL.isDeclspecAttribute()
? (unsigned)diag::warn_unhandled_ms_attribute_ignored
+   : AL.getScopeName()
+   ? (unsigned)diag::ext_unknown_attribute_ignored
: (unsigned)diag::warn_unknown_attribute_ignored)
 << AL << AL.getRange();
 return;
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
index 192fa126109873..c7e66649fb7b22 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
@@ -12,5 +12,5 @@
 [[using clang:]] extern int n; // ok
 [[using blah: clang::optnone]] extern int n; // expected-error {{attribute 
with scope specifier cannot follow}} expected-warning {{only applies to 
functions}}
 
-[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown 
attribute}}
-[[using unknown_ns: something]] extern int n; // expected-warning {{unknown 
attribute}}
+[[using clang: unknown_attr]] extern int n;
+[[using unknown_ns: something]] extern int n;
diff --git a/clang/test/CXX/module/module.interface/p3.cpp 
b/clang/test/CXX/module/module.interface/p3.cpp
index 32819b2dccb11d..3cde92c1a2cf34 100644
--- a/clang/test/CXX/module/module.interface/p3.cpp
+++ b/clang/test/CXX/module/module.interface/p3.cpp
@@ -40,7 +40,7 @@ export { // No diagnostic after P2615R1 DR
   extern "C++" {} // No diagnostic after P2615R1 DR
 }
 export [[]]; // No diagnostic after P2615R1 DR
-export [[example::attr]]; // expected-warning {{unknown attribute 'attr'}}
+export [[example::attr]]; // expected-error {{unknown attribute 'attr'}}
 
 // [...] shall not declare a name with internal linkage
 export static int a; // expected-error {{declaration of 'a' with internal 
linkage cannot be exported}}
diff --git a/clang/test/Lexer/cxx2a-spaceship.cpp 
b/clang/test/Lexer/cxx2a-spaceship.cpp
index 2163a0bf190f90..505f2f47c8ffb8 100644
--- a/clang/test/Lexer/cxx2a-spaceship.cpp
+++ b/clang/test/Lexer/cxx2a-spaceship.cpp
@@ -61,7 +61,7 @@ static_assert(__builtin_strcmp(b, "<=>") == 0);
 // CXX20: preprocess8: <=>=
 
 #define ID(x) x
-[[some_vendor::some_attribu