Skip to content

Commit ee060dc

Browse files
committed
Fix formatting
Created using spr 1.3.5
2 parents ab65708 + 53943de commit ee060dc

File tree

122 files changed

+4505
-5102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+4505
-5102
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6898,6 +6898,8 @@ def module_suffix : Separate<["-"], "module-suffix">, Group<f_Group>, MetaVarNa
68986898
HelpText<"Use <suffix> as the suffix for module files (the default value is `.mod`)">;
68996899
def fno_reformat : Flag<["-"], "fno-reformat">, Group<Preprocessor_Group>,
69006900
HelpText<"Dump the cooked character stream in -E mode">;
6901+
def fpreprocess_include_lines : Flag<["-"], "fpreprocess-include-lines">, Group<Preprocessor_Group>,
6902+
HelpText<"Treat INCLUDE lines like #include directives in -E mode">;
69016903
defm analyzed_objects_for_unparse : OptOutFC1FFlag<"analyzed-objects-for-unparse", "", "Do not use the analyzed objects when unparsing">;
69026904

69036905
def emit_fir : Flag<["-"], "emit-fir">, Group<Action_Group>,

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "clang/AST/OSLog.h"
1515
#include "clang/AST/RecordLayout.h"
1616
#include "clang/Basic/Builtins.h"
17+
#include "clang/Basic/TargetBuiltins.h"
1718
#include "clang/Basic/TargetInfo.h"
1819
#include "llvm/Support/SipHash.h"
1920

@@ -1152,6 +1153,33 @@ static bool interp__builtin_is_aligned_up_down(InterpState &S, CodePtr OpPC,
11521153
return false;
11531154
}
11541155

1156+
static bool interp__builtin_ia32_bextr(InterpState &S, CodePtr OpPC,
1157+
const InterpFrame *Frame,
1158+
const Function *Func,
1159+
const CallExpr *Call) {
1160+
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
1161+
PrimType IndexT = *S.Ctx.classify(Call->getArg(1));
1162+
APSInt Val = peekToAPSInt(S.Stk, ValT,
1163+
align(primSize(ValT)) + align(primSize(IndexT)));
1164+
APSInt Index = peekToAPSInt(S.Stk, IndexT);
1165+
1166+
unsigned BitWidth = Val.getBitWidth();
1167+
uint64_t Shift = Index.extractBitsAsZExtValue(8, 0);
1168+
uint64_t Length = Index.extractBitsAsZExtValue(8, 8);
1169+
Length = Length > BitWidth ? BitWidth : Length;
1170+
1171+
// Handle out of bounds cases.
1172+
if (Length == 0 || Shift >= BitWidth) {
1173+
pushInteger(S, 0, Call->getType());
1174+
return true;
1175+
}
1176+
1177+
uint64_t Result = Val.getZExtValue() >> Shift;
1178+
Result &= llvm::maskTrailingOnes<uint64_t>(Length);
1179+
pushInteger(S, Result, Call->getType());
1180+
return true;
1181+
}
1182+
11551183
static bool interp__builtin_os_log_format_buffer_size(InterpState &S,
11561184
CodePtr OpPC,
11571185
const InterpFrame *Frame,
@@ -1737,6 +1765,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
17371765
return false;
17381766
break;
17391767

1768+
case clang::X86::BI__builtin_ia32_bextr_u32:
1769+
case clang::X86::BI__builtin_ia32_bextr_u64:
1770+
case clang::X86::BI__builtin_ia32_bextri_u32:
1771+
case clang::X86::BI__builtin_ia32_bextri_u64:
1772+
if (!interp__builtin_ia32_bextr(S, OpPC, Frame, F, Call))
1773+
return false;
1774+
break;
1775+
17401776
case Builtin::BI__builtin_os_log_format_buffer_size:
17411777
if (!interp__builtin_os_log_format_buffer_size(S, OpPC, Frame, F, Call))
17421778
return false;

clang/test/CodeGen/tbaa-pointers.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,43 @@ void p2struct(struct S1 **ptr) {
116116
// COMMON-LABEL: define void @p2struct(
117117
// COMMON-SAME: ptr noundef [[PTR:%.+]])
118118
// COMMON: [[PTR_ADDR:%.+]] = alloca ptr, align 8
119-
// ENABLED-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[P2S1_0:!.+]]
120-
// ENABLED-NEXT: [[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[P2S1_0]]
121-
// ENABLED-NEXT: store ptr null, ptr [[BASE]], align 8, !tbaa [[P1S1_:!.+]]
122-
// DEFAULT-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
123-
// DEFAULT-NEXT: [[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
124-
// DEFAULT-NEXT: store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]]
119+
// ENABLED-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR:!.+]]
120+
// DEFAULT-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
121+
// COMMON-NEXT: [[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
122+
// COMMON-NEXT: store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]]
123+
// COMMON-NEXT: ret void
124+
//
125+
*ptr = 0;
126+
}
127+
128+
void p2struct_const(struct S1 const **ptr) {
129+
// COMMON-LABEL: define void @p2struct_const(
130+
// COMMON-SAME: ptr noundef [[PTR:%.+]])
131+
// COMMON: [[PTR_ADDR:%.+]] = alloca ptr, align 8
132+
// COMMON-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
133+
// COMMON-NEXT: [[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
134+
// COMMON-NEXT: store ptr null, ptr [[BASE]], align 8, !tbaa [[ANYPTR]]
125135
// COMMON-NEXT: ret void
126136
//
127137
*ptr = 0;
128138
}
129139

140+
struct S2 {
141+
struct S1 *s;
142+
};
143+
144+
void p2struct2(struct S2 *ptr) {
145+
// COMMON-LABEL: define void @p2struct2(
146+
// COMMON-SAME: ptr noundef [[PTR:%.+]])
147+
// COMMON: [[PTR_ADDR:%.+]] = alloca ptr, align 8
148+
// COMMON-NEXT: store ptr [[PTR]], ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
149+
// COMMON-NEXT: [[BASE:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
150+
// COMMON-NEXT: [[S:%.+]] = getelementptr inbounds nuw %struct.S2, ptr [[BASE]], i32 0, i32 0
151+
// COMMON-NEXT: store ptr null, ptr [[S]], align 8, !tbaa [[S2_S_TAG:!.+]]
152+
// COMMON-NEXT: ret void
153+
ptr->s = 0;
154+
}
155+
130156
// ENABLED: [[P2INT_0]] = !{[[P2INT:!.+]], [[P2INT]], i64 0}
131157
// ENABLED: [[P2INT]] = !{!"p2 int", [[ANY_POINTER:!.+]], i64 0}
132158
// DEFAULT: [[ANYPTR]] = !{[[ANY_POINTER:!.+]], [[ANY_POINTER]], i64 0}
@@ -145,3 +171,5 @@ void p2struct(struct S1 **ptr) {
145171
// ENABLED: [[P2CHAR]] = !{!"p2 omnipotent char", [[ANY_POINTER]], i64 0}
146172
// ENABLED: [[P1CHAR_0]] = !{[[P1CHAR:!.+]], [[P1CHAR]], i64 0}
147173
// ENABLED: [[P1CHAR]] = !{!"p1 omnipotent char", [[ANY_POINTER]], i64 0}
174+
// COMMON: [[S2_S_TAG]] = !{[[S2_TY:!.+]], [[ANY_POINTER]], i64 0}
175+
// COMMON: [[S2_TY]] = !{!"S2", [[ANY_POINTER]], i64 0}

clang/test/CodeGen/tbaa-reference.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,OLD-PATH
2+
// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes -pointer-tbaa %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,OLD-PATH
23
// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -emit-llvm -new-struct-path-tbaa -o - | FileCheck %s -check-prefixes=CHECK,NEW-PATH
4+
// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s -pointer-tbaa -emit-llvm -new-struct-path-tbaa -o - | FileCheck %s -check-prefixes=CHECK,NEW-PATH
35
//
46
// Check that we generate correct TBAA information for reference accesses.
57

flang/include/flang/Common/format.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ template <typename CHAR = char> class FormatValidator {
136136

137137
const CHAR *cursor_{}; // current location in format_
138138
const CHAR *laCursor_{}; // lookahead cursor
139-
TokenKind previousTokenKind_{TokenKind::None};
139+
Token previousToken_{};
140140
Token token_{}; // current token
141141
Token knrToken_{}; // k, n, or r UnsignedInteger token
142142
Token scaleFactorToken_{}; // most recent scale factor token P
@@ -193,7 +193,7 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
193193
// At entry, cursor_ points before the start of the next token.
194194
// At exit, cursor_ points to last CHAR of token_.
195195

196-
previousTokenKind_ = token_.kind();
196+
previousToken_ = token_;
197197
CHAR c{NextChar()};
198198
token_.set_kind(TokenKind::None);
199199
token_.set_offset(cursor_ - format_);
@@ -431,7 +431,7 @@ template <typename CHAR> void FormatValidator<CHAR>::NextToken() {
431431
}
432432
SetLength();
433433
if (stmt_ == IoStmtKind::Read &&
434-
previousTokenKind_ != TokenKind::DT) { // 13.3.2p6
434+
previousToken_.kind() != TokenKind::DT) { // 13.3.2p6
435435
ReportError("String edit descriptor in READ format expression");
436436
} else if (token_.kind() != TokenKind::String) {
437437
ReportError("Unterminated string");
@@ -887,8 +887,10 @@ template <typename CHAR> bool FormatValidator<CHAR>::Check() {
887887
// Possible first token of the next format item; token not yet processed.
888888
if (commaRequired) {
889889
const char *s{"Expected ',' or ')' in format expression"}; // C1302
890-
if (previousTokenKind_ == TokenKind::UnsignedInteger &&
890+
if (previousToken_.kind() == TokenKind::UnsignedInteger &&
891+
previousToken_.length() > 1 &&
891892
itemsWithLeadingInts_.test(token_.kind())) {
893+
// F10.32F10.3 is ambiguous, F10.3F10.3 is not
892894
ReportError(s);
893895
} else {
894896
ReportWarning(s);

flang/include/flang/Frontend/PreprocessorOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ struct PreprocessorOptions {
5656
// -fno-reformat: Emit cooked character stream as -E output
5757
bool noReformat{false};
5858

59+
// -fpreprocess-include-lines: Treat INCLUDE as #include for -E output
60+
bool preprocessIncludeLines{false};
61+
5962
// -dM: Show macro definitions with -dM -E
6063
bool showMacros{false};
6164

flang/include/flang/Parser/parsing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct Options {
4040
bool needProvenanceRangeToCharBlockMappings{false};
4141
Fortran::parser::Encoding encoding{Fortran::parser::Encoding::UTF_8};
4242
bool prescanAndReformat{false}; // -E
43+
bool expandIncludeLinesInPreprocessedOutput{true};
4344
bool showColors{false};
4445
};
4546

flang/lib/Evaluate/fold-implementation.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,9 @@ Expr<TO> FoldOperation(
17361736
msvcWorkaround.context.languageFeatures().ShouldWarn(
17371737
common::UsageWarning::FoldingException)) {
17381738
ctx.messages().Say(
1739-
"INTEGER(%d) to INTEGER(%d) conversion overflowed"_warn_en_US,
1740-
Operand::kind, TO::kind);
1739+
"conversion of %s_%d to INTEGER(%d) overflowed; result is %s"_warn_en_US,
1740+
value->SignedDecimal(), Operand::kind, TO::kind,
1741+
converted.value.SignedDecimal());
17411742
}
17421743
return ScalarConstantToExpr(std::move(converted.value));
17431744
} else if constexpr (FromCat == TypeCategory::Real) {

flang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ static void parsePreprocessorArgs(Fortran::frontend::PreprocessorOptions &opts,
820820
: PPMacrosFlag::Exclude;
821821

822822
opts.noReformat = args.hasArg(clang::driver::options::OPT_fno_reformat);
823+
opts.preprocessIncludeLines =
824+
args.hasArg(clang::driver::options::OPT_fpreprocess_include_lines);
823825
opts.noLineDirectives = args.hasArg(clang::driver::options::OPT_P);
824826
opts.showMacros = args.hasArg(clang::driver::options::OPT_dM);
825827
}
@@ -1486,6 +1488,10 @@ void CompilerInvocation::setFortranOpts() {
14861488
}
14871489
fortranOptions.fixedFormColumns = frontendOptions.fixedFormColumns;
14881490

1491+
// -E
1492+
fortranOptions.prescanAndReformat =
1493+
frontendOptions.programAction == PrintPreprocessedInput;
1494+
14891495
fortranOptions.features = frontendOptions.features;
14901496
fortranOptions.encoding = frontendOptions.encoding;
14911497

flang/lib/Frontend/FrontendAction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ bool FrontendAction::beginSourceFile(CompilerInstance &ci,
9595
getCurrentInput().getIsCUDAFortran());
9696
}
9797

98+
// -fpreprocess-include-lines
99+
invoc.getFortranOpts().expandIncludeLinesInPreprocessedOutput =
100+
invoc.getPreprocessorOpts().preprocessIncludeLines;
101+
98102
// Decide between fixed and free form (if the user didn't express any
99103
// preference, use the file extension to decide)
100104
if (invoc.getFrontendOpts().fortranForm == FortranForm::Unknown) {

0 commit comments

Comments
 (0)