Last active
June 5, 2018 19:29
-
-
Save dabelknap/71bd083cd06b91c5b3cef6a7f4d3d427 to your computer and use it in GitHub Desktop.
Break Clang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
ARGMAX = os.sysconf("SC_ARG_MAX") | |
class TestClang(object): | |
def __init__(self): | |
llvmMax = ARGMAX / 2 | |
self.testArgument = "-DE" | |
self.responseFile = "arguments.resp" | |
self.nArgs = llvmMax / (len(self.testArgument) + 1) | |
self.args = ["clang++", "test.cc", "-o", "test", "@%s" % self.responseFile] | |
def generateResponseFile(self, nargs): | |
with open(self.responseFile, 'w') as respFile: | |
for i in range(nargs): | |
respFile.write("%s\n" % self.testArgument) | |
def runClang(self, nargs): | |
self.generateResponseFile(nargs) | |
return subprocess.call(self.args) | |
def findFailure(self): | |
# walk backward from the approximate LLVM limit until the failure is found | |
for i in range(self.nArgs, 0, -10000): | |
exitcode = self.runClang(i) | |
print i | |
if exitcode != 0: | |
print "Clang failed: ", " ".join(self.args) | |
print "Number of arguments in response file: ", i | |
return | |
test = TestClang() | |
test.findFailure() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment