Commit 8a688571 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r276653:

------------------------------------------------------------------------
r276653 | ssrivastava | 2016-07-25 10:17:06 -0700 (Mon, 25 Jul 2016) | 11 lines

Support '#pragma once' in headers when using PCH
    
The '#pragma once' directive was erroneously ignored when encountered
in the header-file specified in generate-PCH-mode. This resulted in
compile-time errors in some cases with legal code, and also a misleading
warning being produced.

Patch by Warren Ristow!

Differential Revision: http://reviews.llvm.org/D19815

------------------------------------------------------------------------

llvm-svn: 277075
parent a2cc88dc
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -354,7 +354,9 @@ void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
/// HandlePragmaOnce - Handle \#pragma once.  OnceTok is the 'once'.
///
void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
  if (isInPrimaryFile()) {
  // Don't honor the 'once' when handling the primary source file, unless
  // this is a prefix to a TU, which indicates we're generating a PCH file.
  if (isInPrimaryFile() && TUKind != TU_Prefix) {
    Diag(OnceTok, diag::pp_pragma_once_in_main_file);
    return;
  }
+5 −0
Original line number Diff line number Diff line
#pragma once

/* For use with the pragma-once.c test */

int x = 3;
+13 −0
Original line number Diff line number Diff line
// Test this without pch.
// RUN: %clang_cc1 -include %S/Inputs/pragma-once.h -fsyntax-only -verify %s

// Test with pch.
// RUN: %clang_cc1 -emit-pch -o %t %S/Inputs/pragma-once.h
// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s

// expected-no-diagnostics

// Including "pragma-once.h" twice, to verify the 'once' aspect is honored.
#include "Inputs/pragma-once.h"
#include "Inputs/pragma-once.h"
int foo(void) { return 0; }