Author: ahatanak Date: Mon Nov 5 22:26:17 2018 New Revision: 346210 URL: http://llvm.org/viewvc/llvm-project?rev=346210&view=rev Log: os_log: Add a new privacy annotation "sensitive".
This is a stricter privacy annotation than "private", which will be used for data that shouldn’t be logged to disk. For backward compatibility, the "private" bit is set too. rdar://problem/36755912 Modified: cfe/trunk/include/clang/AST/FormatString.h 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/FormatString.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/FormatString.h?rev=346210&r1=346209&r2=346210&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/FormatString.h (original) +++ cfe/trunk/include/clang/AST/FormatString.h Mon Nov 5 22:26:17 2018 @@ -475,13 +475,15 @@ class PrintfSpecifier : public analyze_f OptionalFlag HasObjCTechnicalTerm; // '[tt]' OptionalFlag IsPrivate; // '{private}' OptionalFlag IsPublic; // '{public}' + OptionalFlag IsSensitive; // '{sensitive}' OptionalAmount Precision; public: PrintfSpecifier() : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"), IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "), HasAlternativeForm("#"), HasLeadingZeroes("0"), - HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public") {} + HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public"), + IsSensitive("sensitive") {} static PrintfSpecifier Parse(const char *beg, const char *end); @@ -512,6 +514,9 @@ public: } void setIsPrivate(const char *position) { IsPrivate.setPosition(position); } void setIsPublic(const char *position) { IsPublic.setPosition(position); } + void setIsSensitive(const char *position) { + IsSensitive.setPosition(position); + } void setUsesPositionalArg() { UsesPositionalArg = true; } // Methods for querying the format specifier. @@ -551,6 +556,7 @@ public: const OptionalFlag &hasObjCTechnicalTerm() const { return HasObjCTechnicalTerm; } const OptionalFlag &isPrivate() const { return IsPrivate; } const OptionalFlag &isPublic() const { return IsPublic; } + const OptionalFlag &isSensitive() const { return IsSensitive; } bool usesPositionalArg() const { return UsesPositionalArg; } /// Changes the specifier and length according to a QualType, retaining any Modified: cfe/trunk/include/clang/AST/OSLog.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=346210&r1=346209&r2=346210&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/OSLog.h (original) +++ cfe/trunk/include/clang/AST/OSLog.h Mon Nov 5 22:26:17 2018 @@ -60,7 +60,10 @@ public: IsPrivate = 0x1, // The item is marked "public" in the format string. - IsPublic = 0x2 + IsPublic = 0x2, + + // The item is marked "sensitive" in the format string. + IsSensitive = 0x4 | IsPrivate }; private: @@ -73,7 +76,8 @@ private: public: OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags) : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) { - assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic)) && + assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) || + (Flags == IsSensitive)) && "unexpected privacy flag"); } Modified: cfe/trunk/lib/AST/OSLog.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OSLog.cpp?rev=346210&r1=346209&r2=346210&view=diff ============================================================================== --- cfe/trunk/lib/AST/OSLog.cpp (original) +++ cfe/trunk/lib/AST/OSLog.cpp Mon Nov 5 22:26:17 2018 @@ -120,7 +120,9 @@ public: ArgsData.back().FieldWidth = Args[FS.getFieldWidth().getArgIndex()]; } - if (FS.isPrivate()) + if (FS.isSensitive()) + ArgsData.back().Flags |= OSLogBufferItem::IsSensitive; + else if (FS.isPrivate()) ArgsData.back().Flags |= OSLogBufferItem::IsPrivate; else if (FS.isPublic()) ArgsData.back().Flags |= OSLogBufferItem::IsPublic; Modified: cfe/trunk/lib/AST/PrintfFormatString.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/PrintfFormatString.cpp?rev=346210&r1=346209&r2=346210&view=diff ============================================================================== --- cfe/trunk/lib/AST/PrintfFormatString.cpp (original) +++ cfe/trunk/lib/AST/PrintfFormatString.cpp Mon Nov 5 22:26:17 2018 @@ -127,7 +127,8 @@ static PrintfSpecifierResult ParsePrintf do { StringRef Str(I, E - I); - std::string Match = "^[[:space:]]*(private|public)[[:space:]]*(,|})"; + std::string Match = "^[[:space:]]*(private|public|sensitive)" + "[[:space:]]*(,|})"; llvm::Regex R(Match); SmallVector<StringRef, 2> Matches; @@ -138,7 +139,11 @@ static PrintfSpecifierResult ParsePrintf // Set the privacy flag if the privacy annotation in the // comma-delimited segment is at least as strict as the privacy // annotations in previous comma-delimited segments. - if (MatchedStr.equals("private")) + if (MatchedStr.equals("sensitive")) + PrivacyFlags = clang::analyze_os_log::OSLogBufferItem::IsSensitive; + else if (PrivacyFlags != + clang::analyze_os_log::OSLogBufferItem::IsSensitive && + MatchedStr.equals("private")) PrivacyFlags = clang::analyze_os_log::OSLogBufferItem::IsPrivate; else if (PrivacyFlags == 0 && MatchedStr.equals("public")) PrivacyFlags = clang::analyze_os_log::OSLogBufferItem::IsPublic; @@ -168,6 +173,9 @@ static PrintfSpecifierResult ParsePrintf case clang::analyze_os_log::OSLogBufferItem::IsPublic: FS.setIsPublic(MatchedStr.data()); break; + case clang::analyze_os_log::OSLogBufferItem::IsSensitive: + FS.setIsSensitive(MatchedStr.data()); + break; default: llvm_unreachable("Unexpected privacy flag value"); } Modified: cfe/trunk/test/CodeGen/builtins.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=346210&r1=346209&r2=346210&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/builtins.c (original) +++ cfe/trunk/test/CodeGen/builtins.c Mon Nov 5 22:26:17 2018 @@ -443,10 +443,17 @@ void test_builtin_os_log(void *buf, int // CHECK: call void @__os_log_helper_1_3_1_8_33( __builtin_os_log_format(buf, "%{ xyz, private }s", "abc"); + // CHECK: call void @__os_log_helper_1_3_1_8_37( + __builtin_os_log_format(buf, "%{ xyz, sensitive }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"); + + // CHECK: call void @__os_log_helper_1_3_1_8_37( + __builtin_os_log_format(buf, "%{ private, sensitive, private, public}s", + "abc"); } // CHECK-LABEL: define linkonce_odr hidden void @__os_log_helper_1_3_4_4_0_8_34_4_17_8_49 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits