Skip to content

Commit 0a739eb

Browse files
committed
[clang][Interp] Implement __builtin___{CF,NS}StringMakeConstantString
By doing the same thing the current interpreter does: Just passing on the first parameter.
1 parent abe292f commit 0a739eb

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,9 @@ static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
606606
return true;
607607
}
608608

609-
static bool interp__builtin_launder(InterpState &S, CodePtr OpPC,
610-
const InterpFrame *Frame,
611-
const Function *Func,
612-
const CallExpr *Call) {
609+
/// Just takes the first Argument to the call and puts it on the stack.
610+
static bool noopPointer(InterpState &S, CodePtr OpPC, const InterpFrame *Frame,
611+
const Function *Func, const CallExpr *Call) {
613612
const Pointer &Arg = S.Stk.peek<Pointer>();
614613
S.Stk.push<Pointer>(Arg);
615614
return true;
@@ -1144,7 +1143,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
11441143
break;
11451144

11461145
case Builtin::BI__builtin_launder:
1147-
if (!interp__builtin_launder(S, OpPC, Frame, F, Call))
1146+
case Builtin::BI__builtin___CFStringMakeConstantString:
1147+
case Builtin::BI__builtin___NSStringMakeConstantString:
1148+
if (!noopPointer(S, OpPC, Frame, F, Call))
11481149
return false;
11491150
break;
11501151

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,12 @@ namespace bswap {
510510
int h4 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
511511
int h5 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
512512
}
513+
514+
#define CFSTR __builtin___CFStringMakeConstantString
515+
void test7(void) {
516+
const void *X;
517+
X = CFSTR("\242"); // both-warning {{input conversion stopped}}
518+
X = CFSTR("\0"); // no-warning
519+
X = CFSTR(242); // both-error {{cannot initialize a parameter of type 'const char *' with an rvalue of type 'int'}}
520+
X = CFSTR("foo", "bar"); // both-error {{too many arguments to function call}}
521+
}

0 commit comments

Comments
 (0)