Skip to content

Commit 22bf7c5

Browse files
committed
[clang][Interp] Support __builtin_os_log_format_buffer_size
1 parent c455b46 commit 22bf7c5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

clang/lib/AST/Interp/InterpBuiltin.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Boolean.h"
1010
#include "Interp.h"
1111
#include "PrimType.h"
12+
#include "clang/AST/OSLog.h"
1213
#include "clang/AST/RecordLayout.h"
1314
#include "clang/Basic/Builtins.h"
1415
#include "clang/Basic/TargetInfo.h"
@@ -1088,6 +1089,17 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
10881089
return false;
10891090
}
10901091

1092+
static bool interp__builtin_os_log_format_buffer_size(InterpState &S,
1093+
CodePtr OpPC,
1094+
const InterpFrame *Frame,
1095+
const Function *Func,
1096+
const CallExpr *Call) {
1097+
analyze_os_log::OSLogBufferLayout Layout;
1098+
analyze_os_log::computeOSLogBufferLayout(S.getCtx(), Call, Layout);
1099+
pushInteger(S, Layout.size().getQuantity(), Call->getType());
1100+
return true;
1101+
}
1102+
10911103
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
10921104
const CallExpr *Call) {
10931105
const InterpFrame *Frame = S.Current;
@@ -1409,6 +1421,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
14091421
return false;
14101422
break;
14111423

1424+
case Builtin::BI__builtin_os_log_format_buffer_size:
1425+
if (!interp__builtin_os_log_format_buffer_size(S, OpPC, Frame, F, Call))
1426+
return false;
1427+
break;
1428+
14121429
default:
14131430
S.FFDiag(S.Current->getLocation(OpPC),
14141431
diag::note_invalid_subexpr_in_const_expr)

clang/test/AST/Interp/builtin-functions.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -633,3 +633,9 @@ void test7(void) {
633633
X = CFSTR("foo", "bar"); // both-error {{too many arguments to function call}}
634634
#endif
635635
}
636+
637+
/// The actual value on my machine is 22, but I have a feeling this will be different
638+
/// on other targets, so just checking for != 0 here. Light testing is fine since
639+
/// the actual implementation uses analyze_os_log::computeOSLogBufferLayout(), which
640+
/// is tested elsewhere.
641+
static_assert(__builtin_os_log_format_buffer_size("%{mask.xyz}s", "abc") != 0, "");

0 commit comments

Comments
 (0)