Site Tools


llmcpp-clang-integration

Table of Contents

Clang integration (llmcpp)

Clang integration lets llmcpp check candidate implementations using the surrounding translation unit and captured compiler settings. The checking compiler changes the action and remaps the main source in memory:

FrontendOptions &fo = inv->getFrontendOpts();
fo.ProgramAction = frontend::ParseSyntaxOnly;
fo.OutputFile.clear();
fo.DisableFree = false;
inv->getDependencyOutputOpts() = DependencyOutputOptions();
 
PreprocessorOptions &ppo = inv->getPreprocessorOpts();
ppo.addMacroDef("__llm__=");
ppo.addMacroDef("__LLMCPP__=1");
ppo.addRemappedFile(m_main_file,
                    llvm::MemoryBuffer::getMemBufferCopy(source, m_main_file).release());

ParseSyntaxOnly requests parsing and semantic checks rather than executable output. The remapped buffer contains the candidate body in place of the prompt; the author's source file is not overwritten.

Clang can therefore detect missing declarations, incompatible types, or invalid access in context. It does not execute the function or establish that its behavior matches the request. Behavioral tests address that separate question.

Source: compiler_sandbox.cpp.

llmcpp-clang-integration.md · Last modified: by 127.0.0.1