Skip to content

Commit fe899d8

Browse files
committed
improve c++ fuzzing
1 parent 218ee06 commit fe899d8

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

tests/fuzz/csmith_driver.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@
3939
print 'opt level:', opts
4040

4141
print 'Tried %d, notes: %s' % (tried, notes)
42-
print '1) Generate C'
42+
print '1) Generate source'
4343
extra_args = []
4444
if random.random() < 0.5: extra_args += ['--no-math64']
4545
suffix = '.c'
46+
COMP = shared.CLANG_CC
4647
if random.random() < 0.5:
4748
extra_args += ['--lang-cpp']
4849
suffix += 'pp'
49-
print extra_args
50+
COMP = shared.CLANG
51+
print COMP, extra_args
5052
fullname = filename + suffix
5153
check_call([CSMITH, '--no-volatiles', '--no-packed-struct'] + extra_args,
5254
#['--max-block-depth', '2', '--max-block-size', '2', '--max-expr-complexity', '2', '--max-funcs', '2'],
@@ -57,11 +59,17 @@
5759

5860
print '2) Compile natively'
5961
shared.try_delete(filename)
60-
shared.check_execute([shared.CLANG_CC, opts, fullname, '-o', filename + '1'] + CSMITH_CFLAGS) # + shared.EMSDK_OPTS
61-
shared.check_execute([shared.CLANG_CC, opts, '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', fullname, '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS)
62+
try:
63+
shared.check_execute([COMP, opts, fullname, '-o', filename + '1'] + CSMITH_CFLAGS) # + shared.EMSDK_OPTS
64+
except Exception, e:
65+
print 'Failed to compile natively using clang', e
66+
notes['invalid'] += 1
67+
continue
68+
69+
shared.check_execute([COMP, opts, '-emit-llvm', '-c', '-Xclang', '-triple=i386-pc-linux-gnu', fullname, '-o', filename + '.bc'] + CSMITH_CFLAGS + shared.EMSDK_OPTS)
6270
shared.check_execute([shared.path_from_root('tools', 'nativize_llvm.py'), filename + '.bc'])
6371
shutil.move(filename + '.bc.run', filename + '2')
64-
shared.check_execute([shared.CLANG_CC, fullname, '-o', filename + '3'] + CSMITH_CFLAGS)
72+
shared.check_execute([COMP, fullname, '-o', filename + '3'] + CSMITH_CFLAGS)
6573
print '3) Run natively'
6674
try:
6775
correct1 = shared.jsrun.timeout_run(Popen([filename + '1'], stdout=PIPE, stderr=PIPE), 3)

0 commit comments

Comments
 (0)