brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 03bf01d Raw
64 lines · cpp
1// Test PCHs:2//   MAIN - includes textual_1.h3//        \ loads    pch_1.h - includes textual_2.h4//                           \ loads    pch_2.h5 6// RUN: rm -rf %t7// RUN: mkdir -p %t8// RUN: split-file %s %t9 10// RUN: %clang_cc1 -Wno-unused-value -std=c++20 -emit-pch -o %t/pch_2.h.pch %t/pch_2.h -x c++11// RUN: %clang_cc1 -Wno-unused-value -std=c++20 -include-pch %t/pch_2.h.pch -emit-pch -o %t/pch_1.h.pch %t/pch_1.h -x c++12// RUN: %clang_cc1 -Wno-unused-value -std=c++20 -include-pch %t/pch_1.h.pch -verify %t/main.cpp -Wunsafe-buffer-usage13 14 15//--- textual_1.h16int a(int *s) {17  s[2];  // <- expected warning here18#pragma clang unsafe_buffer_usage begin19  return s[1];20#pragma clang unsafe_buffer_usage end21}22 23//--- textual_2.h24int b(int *s) {25  s[2];  // <- expected warning here26#pragma clang unsafe_buffer_usage begin27  return s[1];28#pragma clang unsafe_buffer_usage end29}30 31//--- pch_1.h32#include "textual_2.h"33 34int c(int *s) {35  s[2];  // <- expected warning here36#pragma clang unsafe_buffer_usage begin37  return s[1];38#pragma clang unsafe_buffer_usage end39}40 41//--- pch_2.h42int d(int *s) {43  s[2];  // <- expected warning here44#pragma clang unsafe_buffer_usage begin45  return s[1];46#pragma clang unsafe_buffer_usage end47}48 49 50//--- main.cpp51#include "textual_1.h"52// expected-warning@textual_1.h:2{{unsafe buffer access}} \53   expected-note@textual_1.h:2{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}54// expected-warning@textual_2.h:2{{unsafe buffer access}} \55   expected-note@textual_2.h:2{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}56// expected-warning@pch_1.h:4{{unsafe buffer access}} \57   expected-note@pch_1.h:4{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}58// expected-warning@pch_2.h:2{{unsafe buffer access}} \59   expected-note@pch_2.h:2{{pass -fsafe-buffer-usage-suggestions to receive code hardening suggestions}}60int main() {61  int s[] = {1, 2, 3};62  return a(s) + b(s) + c(s) + d(s);63}64