Skip to content

Commit cf7b3f8

Browse files
authored
Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (#118186)
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.
1 parent 451a80c commit cf7b3f8

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3423,7 +3423,7 @@ def warn_typecheck_vector_element_sizes_not_equal : Warning<
34233423
def err_ext_vector_component_exceeds_length : Error<
34243424
"vector component access exceeds type %0">;
34253425
def err_ext_vector_component_name_illegal : Error<
3426-
"illegal vector component name '%0'">;
3426+
"illegal vector component name %0">;
34273427
def err_attribute_address_space_negative : Error<
34283428
"address space is negative">;
34293429
def err_attribute_address_space_too_high : Error<

clang/lib/Sema/SemaExprMember.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,11 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK,
434434
if (!HalvingSwizzle && *compStr) {
435435
// We didn't get to the end of the string. This means the component names
436436
// didn't come from the same set *or* we encountered an illegal name.
437-
S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal)
438-
<< StringRef(compStr, 1) << SourceRange(CompLoc);
437+
size_t Offset = compStr - CompName->getNameStart() + 1;
438+
char Fmt[3] = {'\'', *compStr, '\''};
439+
S.Diag(OpLoc.getLocWithOffset(Offset),
440+
diag::err_ext_vector_component_name_illegal)
441+
<< StringRef(Fmt, 3) << SourceRange(CompLoc);
439442
return QualType();
440443
}
441444

clang/test/SemaCXX/vector-bool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ void foo(const bool& X);
8585

8686
// Disallow element-wise access.
8787
bool* ElementRefs() {
88-
eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}}
89-
&eight_bools.z; // expected-error@89 {{illegal vector component name ''z''}}
90-
foo(eight_bools.w); // expected-error@90 {{illegal vector component name ''w''}}
91-
foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}}
88+
eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}}
89+
&eight_bools.z; // expected-error@89 {{illegal vector component name 'z'}}
90+
foo(eight_bools.w); // expected-error@90 {{illegal vector component name 'w'}}
91+
foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}}
9292
}
9393

9494
void Sizeof() {

0 commit comments

Comments
 (0)