#!/bin/sh set -eu base="${TMPDIR-/tmp}/mcpu-cpp-line-control-$$" mkdir -p "$base/inc" trap 'rm -rf "$base"' EXIT HUP INT TERM cat > "$base/inc/one.h" <<'EOT' int header_line = __LINE__; EOT cat > "$base/main.c" <<'EOT' int before = __LINE__; #line 62 "main.y" int after = __LINE__; const char *file_after = __FILE__; #include "one.h" int returned = __LINE__; #define LINE_NUMBER 90 #line LINE_NUMBER "macro-line.y" int macro_line = __LINE__; EOT "$MCPU_CPP" --no-config -I"$base/inc" "$base/main.c" -o "$base/out" # Generated line information uses GNU linemarker syntax, not input #line syntax. if grep '^#line[[:blank:]]' "$base/out" >/dev/null; then exit 1; fi grep "^# 1 \"$base/main.c\"$" "$base/out" >/dev/null grep '^# 62 "main.y"$' "$base/out" >/dev/null grep '^int after = 62;$' "$base/out" >/dev/null grep '^const char \*file_after = "main.y";$' "$base/out" >/dev/null # Flag 1 means entering an included file; flag 2 means returning to its includer. grep "^# 1 \"$base/inc/one.h\" 1$" "$base/out" >/dev/null grep '^# 65 "main.y" 2$' "$base/out" >/dev/null grep '^int returned = 65;$' "$base/out" >/dev/null # Arguments of #line are macro-expanded before interpretation. grep '^# 90 "macro-line.y"$' "$base/out" >/dev/null grep '^int macro_line = 90;$' "$base/out" >/dev/null