-
Notifications
You must be signed in to change notification settings - Fork 350
[Fortran/gfortran] Add a simple not tool to the test suite #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//===- not.cpp - The 'not' testing tool -----------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// Usage: | ||
// not cmd | ||
// Will return true if cmd doesn't crash and returns false. | ||
// not --crash cmd | ||
// Will return true if cmd crashes (e.g. for testing crash reporting). | ||
|
||
// This file is a stripped down version of not.cpp from llvm/utils. This does | ||
// not depend on any LLVM library. | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
#ifdef _WIN32 | ||
#define WIN32_LEAN_AND_MEAN | ||
#define NOMINMAX | ||
#include <windows.h> | ||
#endif | ||
|
||
int main(int argc, const char **argv) { | ||
bool expectCrash = false; | ||
|
||
++argv; | ||
--argc; | ||
|
||
if (argc > 0 && std::string(argv[0]) == "--crash") { | ||
++argv; | ||
--argc; | ||
expectCrash = true; | ||
|
||
// Crash is expected, so disable crash report and symbolization to reduce | ||
// output and avoid potentially slow symbolization. | ||
#ifdef _WIN32 | ||
SetEnvironmentVariableA("LLVM_DISABLE_CRASH_REPORT", "1"); | ||
SetEnvironmentVariableA("LLVM_DISABLE_SYMBOLIZATION", "1"); | ||
#else | ||
setenv("LLVM_DISABLE_CRASH_REPORT", "1", 0); | ||
setenv("LLVM_DISABLE_SYMBOLIZATION", "1", 0); | ||
#endif | ||
} | ||
|
||
if (argc == 0) | ||
return 1; | ||
|
||
std::stringstream ss; | ||
ss << argv[0]; | ||
for (int i = 1; i < argc; ++i) | ||
ss << " " << argv[i]; | ||
std::string cmd = ss.str(); | ||
|
||
int result = std::system(cmd.c_str()); | ||
cabreraam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int retcode = 0; | ||
int signal = 0; | ||
|
||
#ifdef _WIN32 | ||
// Handle abort() in msvcrt -- It has exit code as 3. abort(), aka | ||
// unreachable, should be recognized as a crash. However, some binaries use | ||
// exit code 3 on non-crash failure paths, so only do this if we expect a | ||
// crash. | ||
if (expectCrash && result == 3) { | ||
retcode = 3; | ||
signal = 1; | ||
} else if (errno) { | ||
// If the command interpreter was not found, errno will be set and 0 will | ||
// be returned. It is unlikely that this will happen in our use case, but | ||
// check anyway. | ||
retcode = 1; | ||
signal = 1; | ||
} else { | ||
// On Windows, result is the exit code, except for the special case above. | ||
retcode = result; | ||
signal = 0; | ||
} | ||
#elif defined(WEXITSTATUS) && defined(WTERMSIG) | ||
// On POSIX systems and Solaris, result is a composite value of the exit code | ||
// and, potentially, the signal that caused termination of the command. | ||
retcode = WEXITSTATUS(result); | ||
signal = WTERMSIG(result); | ||
#else | ||
#error "Unsupported system" | ||
#endif | ||
|
||
// If signal is non-zero, the command caused a crash, usually SIGABRT. | ||
if (signal) { | ||
if (expectCrash) | ||
return EXIT_SUCCESS; | ||
return EXIT_FAILURE; | ||
} | ||
|
||
// The command exited normally. If the command was expected to crash, return | ||
// EXIT_FAILURE since EXIT_SUCCESS is returned in the event of an expected | ||
// crash. Otherwise, invert the return code. | ||
if (expectCrash) | ||
return EXIT_FAILURE; | ||
else if (retcode == EXIT_SUCCESS) | ||
return EXIT_FAILURE; | ||
else | ||
return EXIT_SUCCESS; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.