Skip to content

Commit 50b91aa

Browse files
author
git apple-llvm automerger
committed
Merge commit '4ca9a4bb351a' from llvm.org/release/21.x into stable/21.x
2 parents e6b1a6d + 4ca9a4b commit 50b91aa

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9477,9 +9477,9 @@ def NonStringDocs : Documentation {
94779477
let Category = DocCatDecl;
94789478
let Content = [{
94799479
The ``nonstring`` attribute can be applied to the declaration of a variable or
9480-
a field whose type is a character array to specify that the character array is
9481-
not intended to behave like a null-terminated string. This will silence
9482-
diagnostics with code like:
9480+
a field whose type is a character pointer or character array to specify that
9481+
the buffer is not intended to behave like a null-terminated string. This will
9482+
silence diagnostics with code like:
94839483

94849484
.. code-block:: c
94859485

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5153,10 +5153,10 @@ void Sema::AddModeAttr(Decl *D, const AttributeCommonInfo &CI,
51535153

51545154
static void handleNonStringAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
51555155
// This only applies to fields and variable declarations which have an array
5156-
// type.
5156+
// type or pointer type, with character elements.
51575157
QualType QT = cast<ValueDecl>(D)->getType();
5158-
if (!QT->isArrayType() ||
5159-
!QT->getBaseElementTypeUnsafe()->isAnyCharacterType()) {
5158+
if ((!QT->isArrayType() && !QT->isPointerType()) ||
5159+
!QT->getPointeeOrArrayElementType()->isAnyCharacterType()) {
51605160
S.Diag(D->getBeginLoc(), diag::warn_attribute_non_character_array)
51615161
<< AL << AL.isRegularKeywordAttribute() << QT << AL.getRange();
51625162
return;

clang/test/Sema/attr-nonstring.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,11 @@ struct Outer o2[] = {
229229
}
230230
}
231231
};
232+
233+
// The attribute also works with a pointer type, not just an array type.
234+
__attribute__((nonstring)) char *ptr1;
235+
__attribute__((nonstring)) const unsigned char *ptr2;
236+
struct GH150951 {
237+
__attribute__((nonstring)) char *ptr1;
238+
__attribute__((nonstring)) const unsigned char *ptr2;
239+
};

0 commit comments

Comments
 (0)