Author: ahatanak Date: Wed Jul 11 15:19:14 2018 New Revision: 336863 URL: http://llvm.org/viewvc/llvm-project?rev=336863&view=rev Log: os_log: When there are multiple privacy annotations in the format string, choose the strictest one instead of the last.
Also fix an undefined behavior. Move the pointer update to a later point to avoid adding StringRef::npos to the pointer. rdar://problem/40706280 Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp cfe/trunk/test/CodeGen/builtins.c Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=336863&r1=336862&r2=336863&view=diff ============================================================================== --- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original) +++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Wed Jul 11 15:19:14 2018 @@ -135,17 +135,16 @@ static PrintfSpecifierResult ParsePrintf MatchedStr = Matches[1]; I += Matches[0].size(); - // Set the privacy flag if there is a privacy annotation in the - // comma-delimited segment. This overrides any privacy annotations that - // appeared in previous comma-delimited segments. + // 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")) PrivacyFlags = clang::analyze_os_log::OSLogBufferItem::IsPrivate; - else if (MatchedStr.equals("public")) + else if (PrivacyFlags == 0 && MatchedStr.equals("public")) PrivacyFlags = clang::analyze_os_log::OSLogBufferItem::IsPublic; } else { size_t CommaOrBracePos = Str.find_if([](char c) { return c == ',' || c == '}'; }); - I += CommaOrBracePos + 1; if (CommaOrBracePos == StringRef::npos) { // Neither a comma nor the closing brace was found. @@ -153,6 +152,8 @@ static PrintfSpecifierResult ParsePrintf H.HandleIncompleteSpecifier(Start, E - Start); return true; } + + I += CommaOrBracePos + 1; } // Continue until the closing brace is found. } while (*(I - 1) == ','); Modified: cfe/trunk/test/CodeGen/builtins.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=336863&r1=336862&r2=336863&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/builtins.c (original) +++ cfe/trunk/test/CodeGen/builtins.c Wed Jul 11 15:19:14 2018 @@ -421,7 +421,7 @@ void test_builtin_os_log(void *buf, int // CHECK: %[[V5:.*]] = load i8*, i8** %[[DATA_ADDR]] // CHECK: %[[V6:.*]] = ptrtoint i8* %[[V5]] to i64 // CHECK: call void @__os_log_helper_1_3_4_4_0_8_34_4_17_8_49(i8* %[[V1]], i32 %[[V2]], i64 %[[V4]], i32 16, i64 %[[V6]]) - __builtin_os_log_format(buf, "%d %{private,public}s %{public,private}.16P", i, data, data); + __builtin_os_log_format(buf, "%d %{public}s %{private}.16P", i, data, data); // privacy annotations aren't recognized when they are preceded or followed // by non-whitespace characters. @@ -443,7 +443,7 @@ void test_builtin_os_log(void *buf, int // The last privacy annotation in the string wins. // CHECK: call void @__os_log_helper_1_3_1_8_33( - __builtin_os_log_format(buf, "%{ public, private, public, private}s", "abc"); + __builtin_os_log_format(buf, "%{ private, public, 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