Skip to content

Fix double-quotes in diagnostic when attempting to access a ext_vector of bools #118186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

smallp-o-p
Copy link
Contributor

@smallp-o-p smallp-o-p commented Nov 30, 2024

Fixes #116932

  • Remove the quotation marks in the diagnostic message for err_ext_vector_component_name_illegal
  • Pass in the quotation marks directly when reporting an illegal vector component name inside CheckExtVectorComponent
  • Add an offset to the OpLoc passed into S.Diag so the error message arrow points directly to the offending illegal component rather than to the '.' at the start of the component identifier.
  • Modify the vector-bool.cpp element-wise access test case so it (correctly) now only expects a single set of quotes.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 30, 2024

@llvm/pr-subscribers-clang

Author: William Tran-Viet (smallp-o-p)

Changes

Fixes #116932


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

2 Files Affected:

  • (modified) clang/lib/Sema/SemaExprMember.cpp (+3-1)
  • (modified) clang/test/SemaCXX/vector-bool.cpp (+4-4)
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 434768b99d631e..3d843bb84d9d8b 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1655,8 +1655,10 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R,
     // We disallow element access for ext_vector_type bool.  There is no way to
     // materialize a reference to a vector element as a pointer (each element is
     // one bit in the vector).
+    assert(MemberName.isIdentifier() &&
+           "Ext vector component name not an identifier!");
     S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal)
-        << MemberName
+        << MemberName.getAsIdentifierInfo()->getName()
         << (BaseExpr.get() ? BaseExpr.get()->getSourceRange() : SourceRange());
     return ExprError();
   }
diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp
index e99d420e73fab2..cd638056f348b0 100644
--- a/clang/test/SemaCXX/vector-bool.cpp
+++ b/clang/test/SemaCXX/vector-bool.cpp
@@ -85,10 +85,10 @@ void foo(const bool& X);
 
 // Disallow element-wise access.
 bool* ElementRefs() {
-  eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}}
-  &eight_bools.z;        // expected-error@89 {{illegal vector component name ''z''}}
-  foo(eight_bools.w);    // expected-error@90 {{illegal vector component name ''w''}}
-  foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name ''wyx''}}
+  eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}}
+  &eight_bools.z;        // expected-error@89 {{illegal vector component name 'z'}}
+  foo(eight_bools.w);    // expected-error@90 {{illegal vector component name 'w'}}
+  foo(eight_bools.wyx);  // expected-error@91 {{illegal vector component name 'wyx'}}
 }
 
 void Sizeof() {

Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, please add a more detailed summary to your PR. Your summary should if your title describes the problem sufficiently describe how you will fix the problem.

Copy link

github-actions bot commented Dec 14, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@smallp-o-p smallp-o-p force-pushed the 116932-Double-single-quotes-in-"illegal-vector-component-name"-diagnostic branch from 805195c to eb073be Compare December 14, 2024 04:41
…n CheckExtVector(), and offset the diagnostic arrow so it points to the offending component, rather than the '.' at the start of the component identifier.
@smallp-o-p smallp-o-p force-pushed the 116932-Double-single-quotes-in-"illegal-vector-component-name"-diagnostic branch from eb073be to 1bcf418 Compare December 14, 2024 04:55
@smallp-o-p smallp-o-p force-pushed the 116932-Double-single-quotes-in-"illegal-vector-component-name"-diagnostic branch from 5c135e8 to ad89f32 Compare December 15, 2024 01:12
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tbaederr
Copy link
Contributor

Do you need someone to push this?

@smallp-o-p
Copy link
Contributor Author

Yes please.

@tbaederr tbaederr merged commit cf7b3f8 into llvm:main Dec 20, 2024
8 checks passed
@smallp-o-p smallp-o-p deleted the 116932-Double-single-quotes-in-"illegal-vector-component-name"-diagnostic branch April 11, 2025 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double single-quotes in "illegal vector component name" diagnostic
6 participants