https://github.com/smallp-o-p updated 
https://github.com/llvm/llvm-project/pull/118186

>From 3b7cf6e65bdfedf8d15e393c9c2f819c4ed70386 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranv...@proton.me>
Date: Sat, 30 Nov 2024 15:53:32 -0500
Subject: [PATCH 1/3] Fix double-quotes in diagnostic when attempting to access
 a ext_vector of bools

---
 clang/lib/Sema/SemaExprMember.cpp  | 4 +++-
 clang/test/SemaCXX/vector-bool.cpp | 8 ++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

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() {

>From 664ac70ca6b752eaaca6ee64897885a8e19d84c5 Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranv...@proton.me>
Date: Fri, 13 Dec 2024 22:50:24 -0500
Subject: [PATCH 2/3] Remove quotation marks from
 err_ext_vector_component_name_illegal

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..3fe837de467cd0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3423,7 +3423,7 @@ def warn_typecheck_vector_element_sizes_not_equal : 
Warning<
 def err_ext_vector_component_exceeds_length : Error<
   "vector component access exceeds type %0">;
 def err_ext_vector_component_name_illegal : Error<
-  "illegal vector component name '%0'">;
+  "illegal vector component name %0">;
 def err_attribute_address_space_negative : Error<
   "address space is negative">;
 def err_attribute_address_space_too_high : Error<

>From 1bcf41860a914f66ec31eafc739b4e938363ef3c Mon Sep 17 00:00:00 2001
From: William Tran-Viet <wtranv...@proton.me>
Date: Fri, 13 Dec 2024 23:53:29 -0500
Subject: [PATCH 3/3] Pass single quotes directly when reporting illegal vector
 component in CheckExtVector(), and offset the diagnostic arrow so it points
 to the offending component, rather than the '.' at the start of the component
 identifier.

---
 clang/lib/Sema/SemaExprMember.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 3d843bb84d9d8b..70f51efe193b4b 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -434,8 +434,10 @@ CheckExtVectorComponent(Sema &S, QualType baseType, 
ExprValueKind &VK,
   if (!HalvingSwizzle && *compStr) {
     // We didn't get to the end of the string. This means the component names
     // didn't come from the same set *or* we encountered an illegal name.
-    S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal)
-      << StringRef(compStr, 1) << SourceRange(CompLoc);
+    size_t Offset = compStr - CompName->getNameStart() + 1;
+    S.Diag(OpLoc.getLocWithOffset(Offset),
+           diag::err_ext_vector_component_name_illegal)
+        << StringRef({'\'', *compStr, '\''}) << SourceRange(CompLoc);
     return QualType();
   }
 

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

Reply via email to