llvm-project/clang/test/Preprocessor/pragma_microsoft.c
Aaron Ballman 0f1c1be196 [clang] Remove rdar links; NFC
We have a new policy in place making links to private resources
something we try to avoid in source and test files. Normally, we'd
organically switch to the new policy rather than make a sweeping change
across a project. However, Clang is in a somewhat special circumstance
currently: recently, I've had several new contributors run into rdar
links around test code which their patch was changing the behavior of.
This turns out to be a surprisingly bad experience, especially for
newer folks, for a handful of reasons: not understanding what the link
is and feeling intimidated by it, wondering whether their changes are
actually breaking something important to a downstream in some way,
having to hunt down strangers not involved with the patch to impose on
them for help, accidental pressure from asking for potentially private
IP to be made public, etc. Because folks run into these links entirely
by chance (through fixing bugs or working on new features), there's not
really a set of problematic links to focus on -- all of the links have
basically the same potential for causing these problems. As a result,
this is an omnibus patch to remove all such links.

This was not a mechanical change; it was done by manually searching for
rdar, radar, radr, and other variants to find all the various
problematic links. From there, I tried to retain or reword the
surrounding comments so that we would lose as little context as
possible. However, because most links were just a plain link with no
supporting context, the majority of the changes are simple removals.

Differential Review: https://reviews.llvm.org/D158071
2023-08-28 12:13:42 -04:00

259 lines
12 KiB
C

// RUN: %clang_cc1 -triple i686-unknown-windows-msvc %s -fsyntax-only -verify -fms-extensions -Wunknown-pragmas
// RUN: not %clang_cc1 -triple i686-unknown-windows-msvc %s -fms-extensions -E | FileCheck %s
#define FOO 1
#define BAR "2"
#pragma comment(linker,"foo=" FOO) // expected-error {{pragma comment requires parenthesized identifier and optional string}}
// CHECK: #pragma comment(linker,"foo=" 1)
#pragma comment(linker," bar=" BAR)
// CHECK: #pragma comment(linker," bar=" "2")
#pragma comment( user, "Compiled on " __DATE__ " at " __TIME__ )
// CHECK: {{#pragma comment\( user, \"Compiled on \".*\" at \".*\" \)}}
#pragma comment(foo) // expected-error {{unknown kind of pragma comment}}
// CHECK: #pragma comment(foo)
#pragma comment(compiler,) // expected-error {{expected string literal in pragma comment}}
// CHECK: #pragma comment(compiler,)
#define foo compiler
#pragma comment(foo) // macro expand kind.
// CHECK: #pragma comment(compiler)
#pragma comment(foo) x // expected-error {{pragma comment requires}}
// CHECK: #pragma comment(compiler) x
#pragma comment(user, "foo\abar\nbaz\tsome thing")
// CHECK: #pragma comment(user, "foo\abar\nbaz\tsome thing")
#pragma detect_mismatch("test", "1")
// CHECK: #pragma detect_mismatch("test", "1")
#pragma detect_mismatch() // expected-error {{expected string literal in pragma detect_mismatch}}
// CHECK: #pragma detect_mismatch()
#pragma detect_mismatch("test") // expected-error {{pragma detect_mismatch is malformed; it requires two comma-separated string literals}}
// CHECK: #pragma detect_mismatch("test")
#pragma detect_mismatch("test", 1) // expected-error {{expected string literal in pragma detect_mismatch}}
// CHECK: #pragma detect_mismatch("test", 1)
#pragma detect_mismatch("test", BAR)
// CHECK: #pragma detect_mismatch("test", "2")
// __pragma
__pragma(comment(linker," bar=" BAR))
// CHECK: #pragma comment(linker," bar=" "2")
#define MACRO_WITH__PRAGMA { \
__pragma(warning(push)); \
__pragma(warning(disable: 10000)); \
1 + (2 > 3) ? 4 : 5; \
__pragma(warning(pop)); \
}
#define PRAGMA_IN_ARGS(p) p
void f(void)
{
__pragma() // expected-warning{{unknown pragma ignored}}
// CHECK: #pragma
// If we ever actually *support* __pragma(warning(disable: x)),
// this warning should go away.
MACRO_WITH__PRAGMA // expected-warning {{lower precedence}} \
// expected-note 2 {{place parentheses}}
// CHECK: #pragma warning(push)
// CHECK: #pragma warning(disable: 10000)
// CHECK: ; 1 + (2 > 3) ? 4 : 5;
// CHECK: #pragma warning(pop)
// Check that macro arguments can contain __pragma.
PRAGMA_IN_ARGS(MACRO_WITH__PRAGMA) // expected-warning {{lower precedence}} \
// expected-note 2 {{place parentheses}} \
// expected-warning {{expression result unused}}
// CHECK: #pragma warning(push)
// CHECK: #pragma warning(disable: 10000)
// CHECK: ; 1 + (2 > 3) ? 4 : 5;
// CHECK: #pragma warning(pop)
}
// This should include macro_arg_directive even though the include
// is looking for test.h This allows us to assign to "n"
#pragma include_alias("test.h", "macro_arg_directive.h" )
#include "test.h"
void test( void ) {
n = 12;
}
#pragma include_alias(<bar.h>, "bar.h") // expected-warning {{angle-bracketed include <bar.h> cannot be aliased to double-quoted include "bar.h"}}
#pragma include_alias("foo.h", <bar.h>) // expected-warning {{double-quoted include "foo.h" cannot be aliased to angle-bracketed include <bar.h>}}
#pragma include_alias("test.h") // expected-warning {{pragma include_alias expected ','}}
// Make sure that the names match exactly for a replacement, including path information. If
// this were to fail, we would get a file not found error
#pragma include_alias(".\pp-record.h", "does_not_exist.h")
#include "pp-record.h"
#pragma include_alias(12) // expected-warning {{pragma include_alias expected include filename}}
// It's expected that we can map "bar" and <bar> separately
#define test
// We can't actually look up stdio.h because we're using cc1 without header paths, but this will ensure
// that we get the right bar.h, because the "bar.h" will undef test for us, where <bar.h> won't
#pragma include_alias(<bar.h>, <stdio.h>)
#pragma include_alias("bar.h", "pr2086.h") // This should #undef test
#include "bar.h"
#if defined(test)
// This should not warn because test should not be defined
#pragma include_alias("test.h")
#endif
// Test to make sure there are no use-after-free problems
#define B "pp-record.h"
#pragma include_alias("quux.h", B)
void g(int k) {}
#include "quux.h"
// Make sure that empty includes don't work
#pragma include_alias("", "foo.h") // expected-error {{empty filename}}
#pragma include_alias(<foo.h>, <>) // expected-error {{empty filename}}
// Test that we ignore pragma warning.
#pragma warning(push)
// CHECK: #pragma warning(push)
#pragma warning(push, 1)
// CHECK: #pragma warning(push, 1)
#pragma warning(disable : 4705)
// CHECK: #pragma warning(disable: 4705)
#pragma warning(disable : 123 456 789 ; error : 321)
// CHECK: #pragma warning(disable: 123 456 789)
// CHECK: #pragma warning(error: 321)
#pragma warning(once : 321)
// CHECK: #pragma warning(once: 321)
#pragma warning(suppress : 321)
// CHECK: #pragma warning(suppress: 321)
#pragma warning(default : 321)
// CHECK: #pragma warning(default: 321)
#pragma warning(pop)
// CHECK: #pragma warning(pop)
#pragma warning(1: 123)
// CHECK: #pragma warning(1: 123)
#pragma warning(2: 234 567)
// CHECK: #pragma warning(2: 234 567)
#pragma warning(3: 123; 4: 678)
// CHECK: #pragma warning(3: 123)
// CHECK: #pragma warning(4: 678)
#pragma warning(5: 123) // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
#pragma warning(push, 0)
// CHECK: #pragma warning(push, 0)
// FIXME: We could probably support pushing warning level 0.
#pragma warning(pop)
// CHECK: #pragma warning(pop)
#pragma warning // expected-warning {{expected '('}}
#pragma warning( // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
#pragma warning() // expected-warning {{expected 'push', 'pop', 'default', 'disable', 'error', 'once', 'suppress', 1, 2, 3, or 4}}
#pragma warning(push 4) // expected-warning {{expected ')'}}
// CHECK: #pragma warning(push)
#pragma warning(push // expected-warning {{expected ')'}}
// CHECK: #pragma warning(push)
#pragma warning(push, 5) // expected-warning {{requires a level between 0 and 4}}
#pragma warning(pop, 1) // expected-warning {{expected ')'}}
// CHECK: #pragma warning(pop)
#pragma warning(push, 1) asdf // expected-warning {{extra tokens at end of #pragma warning directive}}
// CHECK: #pragma warning(push, 1)
#pragma warning(disable 4705) // expected-warning {{expected ':'}}
#pragma warning(disable : 0) // expected-warning {{expected a warning number}}
#pragma warning(default 321) // expected-warning {{expected ':'}}
#pragma warning(asdf : 321) // expected-warning {{expected 'push', 'pop'}}
#pragma warning(push, -1) // expected-warning {{requires a level between 0 and 4}}
// Test that runtime_checks is parsed but ignored.
#pragma runtime_checks("sc", restore) // no-warning
// Test pragma intrinsic
#pragma intrinsic(memset) // no-warning
#pragma intrinsic(memcpy, strlen, strlen) // no-warning
#pragma intrinsic() // no-warning
#pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
#pragma intrinsic(main) // expected-warning {{'main' is not a recognized builtin; consider including <intrin.h>}}
#pragma intrinsic( // expected-warning {{missing ')' after}}
#pragma intrinsic(int) // expected-warning {{missing ')' after}}
#pragma intrinsic(strcmp) asdf // expected-warning {{extra tokens at end}}
#define __INTRIN_H // there should be no notes after defining __INTRIN_H
#pragma intrinsic(asdf) // expected-warning-re {{'asdf' is not a recognized builtin{{$}}}}
#pragma intrinsic(memset) // no-warning
#undef __INTRIN_H
#pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-pragma-intrinsic"
#pragma intrinsic(asdf) // no-warning
#pragma clang diagnostic pop
#pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-pragmas"
#pragma intrinsic(asdf) // no-warning
#pragma clang diagnostic pop
#pragma intrinsic(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
// Test pragma function
#pragma function(memset) // no-warning
#pragma function(memcpy, strlen, strlen) // no-warning
#pragma function() // no-warning
#pragma function(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
#pragma function(main) // expected-warning {{'main' is not a recognized builtin; consider including <intrin.h>}}
#pragma function( // expected-warning {{missing ')' after}}
#pragma function(int) // expected-warning {{missing ')' after}}
#pragma function(strcmp) asdf // expected-warning {{extra tokens at end}}
#define __INTRIN_H // there should be no notes after defining __INTRIN_H
#pragma function(asdf) // expected-warning-re {{'asdf' is not a recognized builtin{{$}}}}
#pragma function(memset) // no-warning
#undef __INTRIN_H
#pragma function(asdf) // expected-warning {{'asdf' is not a recognized builtin; consider including <intrin.h>}}
// MSVC accepts this, but we decide to reject it based on the MS docs saying the pragma must appear at the global level
void pragma_function_foo() {
#pragma function(memset) // expected-error {{'#pragma function' can only appear at file scope}}
}
#pragma optimize // expected-warning{{missing '(' after '#pragma optimize'}}
#pragma optimize( // expected-warning{{expected string literal in '#pragma optimize'}}
#pragma optimize(a // expected-warning{{expected string literal in '#pragma optimize'}}
#pragma optimize("g" // expected-warning{{expected ',' in '#pragma optimize'}}
#pragma optimize("g", // expected-warning{{missing argument to '#pragma optimize'; expected 'on' or 'off'}}
#pragma optimize("g",xyz // expected-warning{{unexpected argument 'xyz' to '#pragma optimize'; expected 'on' or 'off'}}
#pragma optimize("g",on) // expected-warning{{unexpected argument 'g' to '#pragma optimize'; expected ""}}
#pragma optimize("",on) // no-warning
#pragma optimize("", on) asdf // expected-warning{{extra tokens at end of '#pragma optimize'}}
void pragma_optimize_foo() {
#pragma optimize("", on) // expected-error {{'#pragma optimize' can only appear at file scope}}
}
#pragma managed // no-warning
#pragma unmanaged // no-warning
#pragma managed(push, on) // no-warning
#pragma managed(pop) // no-warning
#pragma managed2 // expected-warning{{unknown pragma ignored}}
#pragma execution_character_set // expected-warning {{expected '('}}
#pragma execution_character_set( // expected-warning {{expected 'push' or 'pop'}}
#pragma execution_character_set() // expected-warning {{expected 'push' or 'pop'}}
#pragma execution_character_set(asdf // expected-warning {{expected 'push' or 'pop'}}
#pragma execution_character_set(asdf) // expected-warning {{expected 'push' or 'pop'}}
#pragma execution_character_set(push // expected-warning {{expected ')'}}
#pragma execution_character_set(pop,) // expected-warning {{expected ')'}}
#pragma execution_character_set(pop,"asdf") // expected-warning {{expected ')'}}
#pragma execution_character_set(push, // expected-error {{expected string literal}}
#pragma execution_character_set(push,) // expected-error {{expected string literal}}
#pragma execution_character_set(push,asdf) // expected-error {{expected string literal}}
#pragma execution_character_set(push, "asdf") // expected-warning {{only 'UTF-8' is supported}}
#pragma execution_character_set(push)
#pragma execution_character_set(push, "utf-8")
#pragma execution_character_set(push, "UTF-8")
#pragma execution_character_set(pop)