Front-end: Fix known crashes by early exit on error (issue #29, issue #34, issue #35).

Added -C option to request cascading errors.  By default, will exit early,
to avoid all error-recovery-based crashes.

This works by simulating end-of-file in input on first error, so no
need for exception handling, or stack unwinding, or any complex error
checking/handling to get out of the stack.
This commit is contained in:
John Kessenich 2016-07-09 14:50:57 -06:00
parent 75b0316f6a
commit a86836ede2
11 changed files with 57 additions and 37 deletions

View file

@ -377,6 +377,9 @@ void C_DECL TParseContext::error(const TSourceLoc& loc, const char* szReason, co
va_start(args, szExtraInfoFormat);
outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixError, args);
va_end(args);
if ((messages & EShMsgCascadingErrors) == 0)
currentScanner->setEndOfInput();
}
void C_DECL TParseContext::warn(const TSourceLoc& loc, const char* szReason, const char* szToken,
@ -397,6 +400,9 @@ void C_DECL TParseContext::ppError(const TSourceLoc& loc, const char* szReason,
va_start(args, szExtraInfoFormat);
outputMessage(loc, szReason, szToken, szExtraInfoFormat, EPrefixError, args);
va_end(args);
if ((messages & EShMsgCascadingErrors) == 0)
currentScanner->setEndOfInput();
}
void C_DECL TParseContext::ppWarn(const TSourceLoc& loc, const char* szReason, const char* szToken,

View file

@ -40,7 +40,7 @@
namespace glslang {
// Use a global end-of-input character, so no tranlation is needed across
// Use a global end-of-input character, so no translation is needed across
// layers of encapsulation. Characters are all 8 bit, and positive, so there is
// no aliasing of character 255 onto -1, for example.
const int EndOfInput = -1;
@ -82,7 +82,8 @@ public:
int get()
{
int ret = peek();
if (ret == EndOfInput) return ret;
if (ret == EndOfInput)
return ret;
++loc[currentSource].column;
++logicalSourceLoc.column;
if (ret == '\n') {
@ -123,7 +124,8 @@ public:
void unget()
{
// Do not roll back once we've reached the end of the file.
if (endOfFileReached) return;
if (endOfFileReached)
return;
if (currentChar > 0) {
--currentChar;
@ -196,6 +198,12 @@ public:
loc[getLastValidSourceIndex()].column = col;
}
void setEndOfInput()
{
endOfFileReached = true;
currentSource = numSources;
}
const TSourceLoc& getSourceLoc() const
{
if (singleLogical) {
@ -255,7 +263,7 @@ protected:
bool singleLogical; // treats the strings as a single logical string.
// locations will be reported from the first string.
// set to true once peak() returns EndOfFile, so that we won't roll back
// Set to true once peek() returns EndOfFile, so that we won't roll back
// once we've reached EndOfFile.
bool endOfFileReached;
};

View file

@ -809,8 +809,8 @@ struct DoPreprocessing {
explicit DoPreprocessing(std::string* string): outputString(string) {}
bool operator()(TParseContextBase& parseContext, TPpContext& ppContext,
TInputScanner& input, bool versionWillBeError,
TSymbolTable& , TIntermediate& ,
EShOptimizationLevel , EShMessages )
TSymbolTable&, TIntermediate&,
EShOptimizationLevel, EShMessages)
{
// This is a list of tokens that do not require a space before or after.
static const std::string unNeededSpaceTokens = ";()[]";