[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 06:10:55 PST 2024


================
@@ -434,8 +434,11 @@ 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;
+    char Fmt[3] = {'\'', *compStr, '\''};
+    S.Diag(OpLoc.getLocWithOffset(Offset),
+           diag::err_ext_vector_component_name_illegal)
+        << StringRef(Fmt, 3) << SourceRange(CompLoc);
----------------
erichkeane wrote:

Can someone explain how this works?  It looks like (both before and after) that we're treating the name length as being only 1 (and in this case, 3 after we're adding the single quote on both sides).  

BUT it seems in test 91 below that the 'wyx' works, but is 3 characters long.  Why can't we just print the entirety of the `IdentifierInfo` above?

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


More information about the cfe-commits mailing list