From 42c8d3380480cbe7826c65dedeabc21d59ce5bf1 Mon Sep 17 00:00:00 2001 From: Akira Hatanaka Date: Tue, 6 Nov 2018 05:41:33 +0000 Subject: [PATCH] os_log: Minor code cleanups. NFC. Also, add a new test case and fix an incorrect comment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@346209 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/OSLog.h | 17 +++++------------ lib/AST/OSLog.cpp | 7 +++---- lib/AST/PrintfFormatString.cpp | 2 +- test/CodeGen/builtins.c | 5 ++++- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/clang/AST/OSLog.h b/include/clang/AST/OSLog.h index 1e60a237b7..41e5c5a9ce 100644 --- a/include/clang/AST/OSLog.h +++ b/include/clang/AST/OSLog.h @@ -72,18 +72,17 @@ private: public: OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags) - : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) {} + : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) { + assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic)) && + "unexpected privacy flag"); + } OSLogBufferItem(ASTContext &Ctx, CharUnits value, unsigned flags) : TheKind(CountKind), ConstValue(value), Size(Ctx.getTypeSizeInChars(Ctx.IntTy)), Flags(flags) {} unsigned char getDescriptorByte() const { - unsigned char result = 0; - if (getIsPrivate()) - result |= IsPrivate; - if (getIsPublic()) - result |= IsPublic; + unsigned char result = Flags; result |= ((unsigned)getKind()) << 4; return result; } @@ -92,7 +91,6 @@ public: Kind getKind() const { return TheKind; } bool getIsPrivate() const { return (Flags & IsPrivate) != 0; } - bool getIsPublic() const { return (Flags & IsPublic) != 0; } const Expr *getExpr() const { return TheExpr; } CharUnits getConstValue() const { return ConstValue; } @@ -120,11 +118,6 @@ public: Items, [](const OSLogBufferItem &Item) { return Item.getIsPrivate(); }); } - bool hasPublicItems() const { - return llvm::any_of( - Items, [](const OSLogBufferItem &Item) { return Item.getIsPublic(); }); - } - bool hasNonScalar() const { return llvm::any_of(Items, [](const OSLogBufferItem &Item) { return Item.getKind() != OSLogBufferItem::ScalarKind; diff --git a/lib/AST/OSLog.cpp b/lib/AST/OSLog.cpp index cf20706c4b..9124fd58a0 100644 --- a/lib/AST/OSLog.cpp +++ b/lib/AST/OSLog.cpp @@ -120,12 +120,11 @@ public: ArgsData.back().FieldWidth = Args[FS.getFieldWidth().getArgIndex()]; } - if (FS.isPrivate()) { + if (FS.isPrivate()) ArgsData.back().Flags |= OSLogBufferItem::IsPrivate; - } - if (FS.isPublic()) { + else if (FS.isPublic()) ArgsData.back().Flags |= OSLogBufferItem::IsPublic; - } + return true; } diff --git a/lib/AST/PrintfFormatString.cpp b/lib/AST/PrintfFormatString.cpp index 96a8f258ed..71c28de99c 100644 --- a/lib/AST/PrintfFormatString.cpp +++ b/lib/AST/PrintfFormatString.cpp @@ -127,7 +127,7 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H, do { StringRef Str(I, E - I); - std::string Match = "^[\t\n\v\f\r ]*(private|public)[\t\n\v\f\r ]*(,|})"; + std::string Match = "^[[:space:]]*(private|public)[[:space:]]*(,|})"; llvm::Regex R(Match); SmallVector Matches; diff --git a/test/CodeGen/builtins.c b/test/CodeGen/builtins.c index 6ca3c414cf..829f725617 100644 --- a/test/CodeGen/builtins.c +++ b/test/CodeGen/builtins.c @@ -440,7 +440,10 @@ void test_builtin_os_log(void *buf, int i, const char *data) { // CHECK: call void @__os_log_helper_1_2_1_8_34( __builtin_os_log_format(buf, "%{ xyz, public }s", "abc"); - // The last privacy annotation in the string wins. + // CHECK: call void @__os_log_helper_1_3_1_8_33( + __builtin_os_log_format(buf, "%{ xyz, private }s", "abc"); + + // The strictest privacy annotation in the string wins. // CHECK: call void @__os_log_helper_1_3_1_8_33( __builtin_os_log_format(buf, "%{ private, public, private, public}s", "abc"); -- 2.50.1