[PATCH] D102122: Support warn_unused_result on typedefs
David Blaikie via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 25 14:25:54 PDT 2022
dblaikie updated this revision to Diff 432131.
dblaikie added a comment.
Separate out clang:warn_unused_result so typedef support can be added to only that spelling.
This has one lingering issue (because it still currently instantiates both the clang:warn_unused_result as the same *Attr class as the others - and so SemaCXX/cxx11-attr-print.cpp is failing because the AST printing for the clang spelling decides to use the C++ standard spelling, I guess because the non-clang Attr class doesn't realize it was spelled with the clang spelling)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102122/new/
https://reviews.llvm.org/D102122
Files:
clang/include/clang/Basic/Attr.td
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/SemaCXX/warn-unused-result.cpp
Index: clang/test/SemaCXX/warn-unused-result.cpp
===================================================================
--- clang/test/SemaCXX/warn-unused-result.cpp
+++ clang/test/SemaCXX/warn-unused-result.cpp
@@ -254,3 +254,15 @@
void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' attribute only applies to functions, classes, or enumerations}}
}
+
+namespace unused_typedef_result {
+[[clang::warn_unused_result]] typedef void *p;
+p f1();
+void f2() {
+ f1(); // expected-warning {{ignoring return value}}
+ void *(*p1)();
+ p1(); // no warning
+ p (*p2)();
+ p2(); // expected-warning {{ignoring return value}}
+}
+}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===================================================================
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -186,6 +186,7 @@
// CHECK-NEXT: VecTypeHint (SubjectMatchRule_function)
// CHECK-NEXT: WarnUnused (SubjectMatchRule_record)
// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: WarnUnusedResultClang (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType, SubjectMatchRule_type_alias)
// CHECK-NEXT: Weak (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
// CHECK-NEXT: WeakRef (SubjectMatchRule_variable, SubjectMatchRule_function)
// CHECK-NEXT: WebAssemblyExportName (SubjectMatchRule_function)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8740,6 +8740,9 @@
case ParsedAttr::AT_WarnUnusedResult:
handleWarnUnusedResult(S, D, AL);
break;
+ case ParsedAttr::AT_WarnUnusedResultClang:
+ handleWarnUnusedResult(S, D, AL);
+ break;
case ParsedAttr::AT_WeakRef:
handleWeakRefAttr(S, D, AL);
break;
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1522,6 +1522,10 @@
if (const auto *A = TD->getAttr<WarnUnusedResultAttr>())
return A;
+ if (const auto *TD = getCallReturnType(Ctx)->getAs<TypedefType>())
+ if (const auto *A = TD->getDecl()->getAttr<WarnUnusedResultAttr>())
+ return A;
+
// Otherwise, see if the callee is marked nodiscard and return that attribute
// instead.
const Decl *D = getCalleeDecl();
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2939,10 +2939,16 @@
let SimpleHandler = 1;
}
+def WarnUnusedResultClang : InheritableAttr {
+ let Spellings = [CXX11<"clang", "warn_unused_result">];
+ let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike, TypedefName]>;
+ let Args = [StringArgument<"Message", 1>];
+ let Documentation = [WarnUnusedResultsDocs];
+}
+
def WarnUnusedResult : InheritableAttr {
let Spellings = [CXX11<"", "nodiscard", 201907>,
C2x<"", "nodiscard", 201904>,
- CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];
let Subjects = SubjectList<[ObjCMethod, Enum, Record, FunctionLike]>;
let Args = [StringArgument<"Message", 1>];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102122.432131.patch
Type: text/x-patch
Size: 3552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220525/733319f8/attachment-0001.bin>
More information about the cfe-commits
mailing list