]> granicus.if.org Git - clang/commitdiff
os_log: Minor code cleanups. NFC.
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 6 Nov 2018 05:41:33 +0000 (05:41 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 6 Nov 2018 05:41:33 +0000 (05:41 +0000)
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
lib/AST/OSLog.cpp
lib/AST/PrintfFormatString.cpp
test/CodeGen/builtins.c

index 1e60a237b770ff162bde9d31068aaaf40357cc56..41e5c5a9cede96604ccd80cb44392d02f8bcc057 100644 (file)
@@ -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;
index cf20706c4b3ac9e0a0eaef3ec47c7976251a819a..9124fd58a05cd3549b4ece46daaa1b603d23a420 100644 (file)
@@ -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;
   }
 
index 96a8f258ed36202d50986a3c7853e44edde34010..71c28de99c9fe8cacb7cbd7d7ef18b55347dfce6 100644 (file)
@@ -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<StringRef, 2> Matches;
 
index 6ca3c414cf31d582b21aec1a2f80b4fa2bb8684b..829f725617fb13d8da1082f43419f6a037009b40 100644 (file)
@@ -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");