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

William Tran-Viet via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 06:34:47 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);
----------------
smallp-o-p wrote:

This is the error path for when you try to mix different accessor types on openCL vector types, which allows you to access them [with this syntax](https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#vector-components) but disallows mixing the different styles.

For example, trying to do something like `.rgbz` where `z` is the bad accessor--here we're mixing the `xyzw` access style with the `rgba` access style. This should result in an error, as evidenced by the [test(s) here](https://github.com/llvm/llvm-project/blob/d866005f6928a2a97e67866bedb26139d8cc27d9/clang/test/Sema/ext_vector_components.c#L46)  

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


More information about the cfe-commits mailing list