Skip to content

[clang][bytecode] Don't create Function instances for builtins #137618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4798,10 +4798,6 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
return true;
}

const Function *Func = getFunction(E->getDirectCallee());
if (!Func)
return false;

// For these, we're expected to ultimately return an APValue pointing
// to the CallExpr. This is needed to get the correct codegen.
if (BuiltinID == Builtin::BI__builtin___CFStringMakeConstantString ||
Expand Down Expand Up @@ -4833,7 +4829,7 @@ bool Compiler<Emitter>::VisitBuiltinCallExpr(const CallExpr *E,
}
}

if (!this->emitCallBI(Func, E, BuiltinID, E))
if (!this->emitCallBI(E, BuiltinID, E))
return false;

if (DiscardResult && !ReturnType->isVoidType()) {
Expand Down
1 change: 0 additions & 1 deletion clang/lib/AST/ByteCode/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
HasRVO(HasRVO) {
if (const auto *F = dyn_cast<const FunctionDecl *>(Source)) {
Variadic = F->isVariadic();
BuiltinID = F->getBuiltinID();
if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
Virtual = CD->isVirtual();
Kind = FunctionKind::Ctor;
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/AST/ByteCode/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ class Function final {

bool isVariadic() const { return Variadic; }

unsigned getBuiltinID() const { return BuiltinID; }

bool isBuiltin() const { return getBuiltinID() != 0; }

unsigned getNumParams() const { return ParamTypes.size(); }

/// Returns the number of parameter this function takes when it's called,
Expand Down Expand Up @@ -296,7 +292,6 @@ class Function final {
bool Defined = false;
bool Variadic = false;
bool Virtual = false;
unsigned BuiltinID = 0;

public:
/// Dumps the disassembled bytecode to \c llvm::errs().
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1607,15 +1607,15 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
return true;
}

bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
const CallExpr *CE, uint32_t BuiltinID) {
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE,
uint32_t BuiltinID) {
// A little arbitrary, but the current interpreter allows evaluation
// of builtin functions in this mode, with some exceptions.
if (BuiltinID == Builtin::BI__builtin_operator_new &&
S.checkingPotentialConstantExpression())
return false;

return InterpretBuiltin(S, OpPC, Func, CE, BuiltinID);
return InterpretBuiltin(S, OpPC, CE, BuiltinID);
}

bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
uint32_t VarArgSize);
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
uint32_t VarArgSize);
bool CallBI(InterpState &S, CodePtr OpPC, const Function *Func,
const CallExpr *CE, uint32_t BuiltinID);
bool CallBI(InterpState &S, CodePtr OpPC, const CallExpr *CE,
uint32_t BuiltinID);
bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
const CallExpr *CE);
bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T);
Expand Down Expand Up @@ -302,8 +302,8 @@ bool CheckDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR);
bool Interpret(InterpState &S);

/// Interpret a builtin function.
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
const CallExpr *Call, uint32_t BuiltinID);
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
uint32_t BuiltinID);

/// Interpret an offsetof operation.
bool InterpretOffsetOf(InterpState &S, CodePtr OpPC, const OffsetOfExpr *E,
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2184,8 +2184,8 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
return true;
}

bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
const CallExpr *Call, uint32_t BuiltinID) {
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
uint32_t BuiltinID) {
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
return Invalid(S, OpPC);

Expand Down
2 changes: 0 additions & 2 deletions clang/lib/AST/ByteCode/InterpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ static void print(llvm::raw_ostream &OS, const T &V, ASTContext &ASTCtx,
}

static bool shouldSkipInBacktrace(const Function *F) {
if (F->isBuiltin())
return true;
if (F->isLambdaStaticInvoker())
return true;

Expand Down
4 changes: 1 addition & 3 deletions clang/lib/AST/ByteCode/Opcodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ def CallVirt : Opcode {
let Args = [ArgFunction, ArgUint32];
}

def CallBI : Opcode {
let Args = [ArgFunction, ArgCallExpr, ArgUint32];
}
def CallBI : Opcode { let Args = [ArgCallExpr, ArgUint32]; }

def CallPtr : Opcode {
let Args = [ArgUint32, ArgCallExpr];
Expand Down