llvm-project/clang/test/Preprocessor/pragma-missing-string-token.c
Alex Lorenz 979d0ee8ab [clang] fix out of bounds access in an empty string when lexing a _Pragma with missing string token
The lexer can attempt to lex a _Pragma and crash with an out of bounds string access when it's
lexing a _Pragma whose string token is an invalid buffer, e.g. when a module header file from which the macro
expansion for that token was deleted from the file system.

Differential Revision: https://reviews.llvm.org/D116052
2022-02-02 11:16:11 -08:00

28 lines
584 B
C

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -emit-module -x c -fmodules -I %t/Inputs -fmodule-name=aa %t/Inputs/module.modulemap -o %t/aa.pcm
// RUN: rm %t/Inputs/b.h
// RUN: not %clang_cc1 -E -fmodules -I %t/Inputs -fmodule-file=%t/aa.pcm %s -o - -fallow-pcm-with-compiler-errors 2>&1 | FileCheck %s
//--- Inputs/module.modulemap
module aa {
header "a.h"
header "b.h"
}
//--- Inputs/a.h
#define TEST(x) x
//--- Inputs/b.h
#define SUB "mypragma"
//--- test.c
#include "a.h"
_Pragma(SUB);
int a = TEST(SUB);
// CHECK: int a
// CHECK: 1 error generated