File size: 7,072 Bytes
955ae84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# CG-Bench: A Call Graph Construction Benchmark for Language Models

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Paper](https://img.shields.io/badge/Paper-PDF-red.svg)](CG_Bench_Can_Language_Models_Assist_Call_Graph_Construction_in_the_Real_World.pdf)

> **πŸ“„ Paper**: [CG-Bench: Can Language Models Assist Call Graph Construction in the Real World?](CG_Bench_Can_Language_Models_Assist_Call_Graph_Construction_in_the_Real_World.pdf) - Published at LMPL@SPLASH2025

CG-Bench is a comprehensive benchmark dataset designed to evaluate the capabilities of Large Language Models (LLMs) in assisting with call graph construction in real-world C/C++ codebases. The benchmark focuses specifically on challenging indirect function calls through function pointers, which are notoriously difficult for traditional static analysis tools to resolve.

## πŸ“‹ Overview

Call graph construction is a fundamental program analysis technique crucial for various software engineering tasks including debugging, optimization, security analysis, and program comprehension. While direct function calls are straightforward to analyze, indirect calls through function pointers present significant challenges for automated tools.

This benchmark provides:
- **Real-world complexity**: Examples extracted from popular open-source projects
- **Diverse patterns**: Multiple categories of function pointer usage patterns
- **Structured format**: Consistent annotation format for evaluation
- **Comprehensive coverage**: 104 examples across 7 major open-source projects

## πŸ—‚οΈ Dataset Structure

### Projects Included
The benchmark includes examples from seven major C/C++ projects:

| Project | Domain | Lines of Code(KLoC) | Description |
|---------|--------|---------------|-------------|
| **openssh** | Security | ~120 | Secure Shell (SSH) protocol implementation |
| **curl** | Networking | ~182 | Command line tool and library for transferring data |
| **redis** | Database | ~200 | In-memory data structure store |
| **zfs** | File System | ~380 | ZFS file system implementation |
| **wrk** | Benchmarking | ~601 | HTTP benchmarking tool |
| **ffmpeg** | Multimedia | ~1,257 | Complete multimedia framework |
| **gcc** | Compiler | ~6,200 | GNU Compiler Collection |
| **Total** | **All Domains** | **~8,940** | **7 major open-source projects** |

### Function Pointer Categories

The benchmark categorizes function pointer usage patterns into 11 distinct types:

1. **`fnptr-callback`** (15 examples): Function pointers used as callbacks
2. **`fnptr-cast`** (7 examples): Function pointers with type casting
3. **`fnptr-dynamic-call`** (5 examples): Dynamically resolved function calls
4. **`fnptr-global-array`** (6 examples): Function pointers in global arrays
5. **`fnptr-global-struct-array`** (12 examples): Function pointers in arrays within global structures
6. **`fnptr-global-struct`** (11 examples): Function pointers in global structures
7. **`fnptr-library`** (20 examples): Function pointers in library interfaces
8. **`fnptr-only`** (12 examples): Basic function pointer calls without complex patterns
9. **`fnptr-struct`** (14 examples): Function pointers stored in structures
10. **`fnptr-varargs`** (1 example): Function pointers with variable arguments
11. **`fnptr-virtual`** (1 example): Virtual function-like patterns in C

## πŸ“ Repository Contents

```
CG-Bench/
β”œβ”€β”€ README.md                         # This file
β”œβ”€β”€ LICENSE                           # MIT License
β”œβ”€β”€ projects.md                       # Detailed project statistics
β”œβ”€β”€ extract_from_markdowns.py         # Data extraction script
β”œβ”€β”€ fnptr-*.md                        # Category-specific examples
└── CG_Bench_Can_Language_Models_Assist_Call_Graph_Construction_in_the_Real_World.pdf
```

### Example Format

Each example follows a consistent structure:

```markdown
# Example N

## Callsite
*Full path and location of the function pointer call*

fnptr: *function_pointer_name*
targets: target_function1, target_function2, ...

## Related Code Snippets
```c
// Relevant code context showing the function pointer usage
```

## πŸš€ Usage

### Extracting Benchmark Data

To generate a structured JSON dataset from the markdown files:

```bash
python3 extract_from_markdowns.py
```

This creates `cgbench.json` containing all examples in a structured format suitable for evaluation.

### Data Format

The generated JSON follows this structure:

```json
{
  "project_name": {
    "callsite_path": {
      "callsite": "function_pointer_name",
      "type": "category",
      "chain_summary": [
        {
          "source_code": ["line1", "line2", ...],
          "parent": ""
        }
      ],
      "callees": {
        "targets": {
          "target_function": ""
        }
      }
    }
  }
}
```

## πŸ“Š Benchmark Statistics

- **Total Examples**: 104
- **Project Categories**: 7 major open-source projects
- **Function Pointer Patterns**: 11 distinct categories
- **Code Contexts**: Multiple code snippets per example showing usage patterns
- **Real-world Complexity**: Examples from production codebases

## 🎯 Use Cases

This benchmark is designed for:

1. **LLM Evaluation**: Assessing language models' ability to understand complex code patterns
2. **Tool Development**: Benchmarking static analysis tools for call graph construction
3. **Research**: Studying function pointer resolution in real-world codebases
4. **Education**: Understanding various function pointer usage patterns in C/C++

## πŸ“– Paper Reference

This benchmark accompanies the research paper:
**"CG-Bench: Can Language Models Assist Call Graph Construction in the Real World?"**

The paper provides detailed methodology, evaluation results, and analysis of LLM performance on call graph construction tasks.

## 🀝 Contributing

We welcome contributions to expand the benchmark! Please consider:

- Adding examples from additional open-source projects
- Identifying new function pointer usage patterns
- Improving the extraction and annotation process
- Reporting issues or inconsistencies

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## πŸ”— Citation

If you use this benchmark in your research, please cite:

```bibtex
@inproceedings{cgbench2025,
  title={CG-Bench: Can Language Models Assist Call Graph Construction in the Real World?},
  author={[Authors]},
  booktitle={Proceedings of the 1st ACM SIGPLAN International Workshop on Language Models for Programming (LMPL 2025)},
  year={2025},
  publisher={ACM},
  address={New York, NY, USA},
  url={https://conf.researchr.org/home/icfp-splash-2025/lmpl-2025},
  note={Co-located with SPLASH 2025}
}
```

## πŸ“ž Contact

For questions or collaboration opportunities, please open an issue on GitHub or contact the maintainers.

---

**Keywords**: Call Graph Construction, Function Pointers, Static Analysis, Large Language Models, C/C++ Analysis, Software Engineering, Program Analysis