Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI Unixish
name: CI-unixish

on: [push, pull_request]

Expand Down Expand Up @@ -28,43 +28,48 @@ jobs:
- name: make test
run: make -j$(nproc) test CXX=${{ matrix.compiler }}

- name: selfcheck
run: |
make -j$(nproc) selfcheck CXX=${{ matrix.compiler }}

- name: Run valgrind
if: matrix.os == 'ubuntu-22.04'
run: |
make clean
# this valgrind version doesn't support DWARF 5 yet
make -j$(nproc) CXX=${{ matrix.compiler }} CXXFLAGS="-gdwarf-4"
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./testrunner
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./simplecpp simplecpp.cpp -e

- name: Run with libstdc++ debug mode
if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'g++'
run: |
make clean
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-g3 -D_GLIBCXX_DEBUG"
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-g3 -D_GLIBCXX_DEBUG"

- name: Run with libc++ debug mode
if: matrix.os == 'ubuntu-22.04' && matrix.compiler == 'clang++'
run: |
make clean
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-stdlib=libc++ -g3 -D_LIBCPP_ENABLE_ASSERTIONS=1" LDFLAGS="-lc++"
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-stdlib=libc++ -g3 -D_LIBCPP_ENABLE_ASSERTIONS=1" LDFLAGS="-lc++"

- name: Run AddressSanitizer
if: matrix.os == 'ubuntu-22.04'
run: |
make clean
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address"
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=address" LDFLAGS="-fsanitize=address"
env:
ASAN_OPTIONS: detect_stack_use_after_return=1

- name: Run UndefinedBehaviorSanitizer
if: matrix.os == 'ubuntu-22.04'
run: |
make clean
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow"
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDFLAGS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow"

# TODO: requires instrumented libc++
- name: Run MemorySanitizer
if: false && matrix.os == 'ubuntu-22.04' && matrix.compiler == 'clang++'
run: |
make clean
make -j$(nproc) test CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory"
make -j$(nproc) test selfcheck CXX=${{ matrix.compiler }} CXXFLAGS="-O2 -g3 -stdlib=libc++ -fsanitize=memory" LDFLAGS="-lc++ -fsanitize=memory"
4 changes: 4 additions & 0 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ jobs:
- name: Test
run: |
.\${{ matrix.config }}\testrunner.exe || exit /b !errorlevel!

- name: Selfcheck
run: |
.\${{ matrix.config }}\simplecpp.exe simplecpp.cpp -e || exit /b !errorlevel!

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ test: testrunner simplecpp
./testrunner
python3 run-tests.py

selfcheck: simplecpp
./selfcheck.sh

simplecpp: main.o simplecpp.o
$(CXX) $(LDFLAGS) main.o simplecpp.o -o simplecpp

Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ build_script:

test_script:
- debug\testrunner.exe
- debug\simplecpp.exe simplecpp.cpp -e
33 changes: 30 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,34 @@ int main(int argc, char **argv)
// Settings..
simplecpp::DUI dui;
bool quiet = false;
bool error_only = false;
for (int i = 1; i < argc; i++) {
const char * const arg = argv[i];
if (*arg == '-') {
bool found = false;
const char c = arg[1];
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
switch (c) {
case 'D': // define symbol
{
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
dui.defines.push_back(value);
found = true;
break;
}
case 'U': // undefine symbol
{
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
dui.undefined.insert(value);
found = true;
break;
}
case 'I': // include path
{
const char * const value = arg[2] ? (argv[i] + 2) : argv[++i];
dui.includePaths.push_back(value);
found = true;
break;
}
case 'i':
if (std::strncmp(arg, "-include=",9)==0) {
dui.includes.push_back(arg+9);
Expand All @@ -70,11 +79,18 @@ int main(int argc, char **argv)
quiet = true;
found = true;
break;
case 'e':
error_only = true;
found = true;
break;
}
if (!found) {
std::cout << "Option '" << arg << "' is unknown." << std::endl;
std::cout << "error: option '" << arg << "' is unknown." << std::endl;
error = true;
}
} else if (filename) {
std::cout << "error: multiple filenames specified" << std::endl;
std::exit(1);
} else {
filename = arg;
}
Expand All @@ -83,6 +99,11 @@ int main(int argc, char **argv)
if (error)
std::exit(1);

if (quiet && error_only) {
std::cout << "error: -e cannot be used in conjunction with -q" << std::endl;
std::exit(1);
}

if (!filename) {
std::cout << "Syntax:" << std::endl;
std::cout << "simplecpp [options] filename" << std::endl;
Expand All @@ -93,6 +114,7 @@ int main(int argc, char **argv)
std::cout << " -std=STD Specify standard." << std::endl;
std::cout << " -q Quiet mode (no output)." << std::endl;
std::cout << " -is Use std::istream interface." << std::endl;
std::cout << " -e Output errors only." << std::endl;
std::exit(0);
}

Expand All @@ -102,6 +124,10 @@ int main(int argc, char **argv)
simplecpp::TokenList *rawtokens;
if (use_istream) {
std::ifstream f(filename);
if (!f.is_open()) {
std::cout << "error: could not open file '" << filename << "'" << std::endl;
std::exit(1);
}
rawtokens = new simplecpp::TokenList(f, files,filename,&outputList);
}
else {
Expand All @@ -118,7 +144,8 @@ int main(int argc, char **argv)

// Output
if (!quiet) {
std::cout << outputTokens.stringify() << std::endl;
if (!error_only)
std::cout << outputTokens.stringify() << std::endl;

for (const simplecpp::Output &output : outputList) {
std::cerr << output.location.file() << ':' << output.location.line << ": ";
Expand Down
6 changes: 6 additions & 0 deletions selfcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

output=$(./simplecpp simplecpp.cpp -e 2>&1)
ec=$?
echo "$output" | grep -v 'Header not found: <'
exit $ec