r346209 - os_log: Minor code cleanups. NFC.

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 5 21:41:33 PST 2018


Author: ahatanak
Date: Mon Nov  5 21:41:33 2018
New Revision: 346209

URL: http://llvm.org/viewvc/llvm-project?rev=346209&view=rev
Log:
os_log: Minor code cleanups. NFC.

Also, add a new test case and fix an incorrect comment.

Modified:
    cfe/trunk/include/clang/AST/OSLog.h
    cfe/trunk/lib/AST/OSLog.cpp
    cfe/trunk/lib/AST/PrintfFormatString.cpp
    cfe/trunk/test/CodeGen/builtins.c

Modified: cfe/trunk/include/clang/AST/OSLog.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=346209&r1=346208&r2=346209&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/OSLog.h (original)
+++ cfe/trunk/include/clang/AST/OSLog.h Mon Nov  5 21:41:33 2018
@@ -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;

Modified: cfe/trunk/lib/AST/OSLog.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OSLog.cpp?rev=346209&r1=346208&r2=346209&view=diff
==============================================================================
--- cfe/trunk/lib/AST/OSLog.cpp (original)
+++ cfe/trunk/lib/AST/OSLog.cpp Mon Nov  5 21:41:33 2018
@@ -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;
   }
 

Modified: cfe/trunk/lib/AST/PrintfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/PrintfFormatString.cpp?rev=346209&r1=346208&r2=346209&view=diff
==============================================================================
--- cfe/trunk/lib/AST/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/AST/PrintfFormatString.cpp Mon Nov  5 21:41:33 2018
@@ -127,7 +127,7 @@ static PrintfSpecifierResult ParsePrintf
 
     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;
 

Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=346209&r1=346208&r2=346209&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Mon Nov  5 21:41:33 2018
@@ -440,7 +440,10 @@ void test_builtin_os_log(void *buf, int
   // 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");




More information about the cfe-commits mailing list