Skip to content

Commit

Permalink
Fix double-quotes in diagnostic when attempting to access a ext_vecto…
Browse files Browse the repository at this point in the history
…r of bools (llvm#118186)

Fixes llvm#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.
  • Loading branch information
smallp-o-p authored Dec 20, 2024
1 parent 451a80c commit cf7b3f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaExprMember.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
return QualType();
}

Expand Down
8 changes: 4 additions & 4 deletions clang/test/SemaCXX/vector-bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit cf7b3f8

Please sign in to comment.