Skip to content

Commit 35e7b54

Browse files
authored
Merge branch 'main' into revert-141853-scf_for_bug
2 parents 2238fd9 + 452276e commit 35e7b54

File tree

47 files changed

+1155
-315
lines changed

Some content is hidden

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

47 files changed

+1155
-315
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
139139
}
140140

141141
bool isSized(mlir::Type ty) {
142-
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType,
143-
cir::IntType>(ty))
142+
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType, cir::IntType,
143+
cir::CIRFPTypeInterface, cir::ComplexType, cir::RecordType>(
144+
ty))
144145
return true;
145146

146147
if (const auto vt = mlir::dyn_cast<cir::VectorType>(ty))

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,15 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
419419
case Type::ConstantArray: {
420420
const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty);
421421
mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
422+
423+
// TODO(CIR): In LLVM, "lower arrays of undefined struct type to arrays of
424+
// i8 just to have a concrete type"
425+
if (!builder.isSized(elemTy)) {
426+
cgm.errorNYI(SourceLocation(), "arrays of undefined struct type", type);
427+
resultType = cgm.UInt32Ty;
428+
break;
429+
}
430+
422431
resultType = cir::ArrayType::get(elemTy, arrTy->getSize().getZExtValue());
423432
break;
424433
}
@@ -432,8 +441,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
432441
}
433442

434443
case Type::Enum: {
435-
const EnumDecl *ED = cast<EnumType>(ty)->getDecl();
436-
if (auto integerType = ED->getIntegerType(); !integerType.isNull())
444+
const EnumDecl *ed = cast<EnumType>(ty)->getDecl();
445+
if (auto integerType = ed->getIntegerType(); !integerType.isNull())
437446
return convertType(integerType);
438447
// Return a placeholder 'i32' type. This can be changed later when the
439448
// type is defined (see UpdateCompletedType), but is likely to be the

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,6 @@ static unsigned skipNewline(const char *&First, const char *End) {
323323
return Len;
324324
}
325325

326-
static bool wasLineContinuation(const char *First, unsigned EOLLen) {
327-
return *(First - (int)EOLLen - 1) == '\\';
328-
}
329-
330326
static void skipToNewlineRaw(const char *&First, const char *const End) {
331327
for (;;) {
332328
if (First == End)
@@ -336,13 +332,16 @@ static void skipToNewlineRaw(const char *&First, const char *const End) {
336332
if (Len)
337333
return;
338334

335+
char LastNonWhitespace = ' ';
339336
do {
337+
if (!isHorizontalWhitespace(*First))
338+
LastNonWhitespace = *First;
340339
if (++First == End)
341340
return;
342341
Len = isEOL(First, End);
343342
} while (!Len);
344343

345-
if (First[-1] != '\\')
344+
if (LastNonWhitespace != '\\')
346345
return;
347346

348347
First += Len;
@@ -394,6 +393,7 @@ static bool isQuoteCppDigitSeparator(const char *const Start,
394393
}
395394

396395
void Scanner::skipLine(const char *&First, const char *const End) {
396+
char LastNonWhitespace = ' ';
397397
for (;;) {
398398
assert(First <= End);
399399
if (First == End)
@@ -419,6 +419,8 @@ void Scanner::skipLine(const char *&First, const char *const End) {
419419
// Iterate over comments correctly.
420420
if (*First != '/' || End - First < 2) {
421421
LastTokenPtr = First;
422+
if (!isWhitespace(*First))
423+
LastNonWhitespace = *First;
422424
++First;
423425
continue;
424426
}
@@ -431,6 +433,8 @@ void Scanner::skipLine(const char *&First, const char *const End) {
431433

432434
if (First[1] != '*') {
433435
LastTokenPtr = First;
436+
if (!isWhitespace(*First))
437+
LastNonWhitespace = *First;
434438
++First;
435439
continue;
436440
}
@@ -442,8 +446,9 @@ void Scanner::skipLine(const char *&First, const char *const End) {
442446
return;
443447

444448
// Skip over the newline.
445-
unsigned Len = skipNewline(First, End);
446-
if (!wasLineContinuation(First, Len)) // Continue past line-continuations.
449+
skipNewline(First, End);
450+
451+
if (LastNonWhitespace != '\\')
447452
break;
448453
}
449454
}
@@ -468,9 +473,16 @@ static void skipWhitespace(const char *&First, const char *const End) {
468473
if (End - First < 2)
469474
return;
470475

471-
if (First[0] == '\\' && isVerticalWhitespace(First[1])) {
472-
skipNewline(++First, End);
473-
continue;
476+
if (*First == '\\') {
477+
const char *Ptr = First + 1;
478+
while (Ptr < End && isHorizontalWhitespace(*Ptr))
479+
++Ptr;
480+
if (Ptr != End && isVerticalWhitespace(*Ptr)) {
481+
skipNewline(Ptr, End);
482+
First = Ptr;
483+
continue;
484+
}
485+
return;
474486
}
475487

476488
// Check for a non-comment character.

clang/test/CIR/CodeGen/array.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,26 @@ void func10(int *a) {
473473
// OGCG: %[[ELE:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 5
474474
// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4
475475
// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
476+
477+
void func11() { int _Complex a[4]; }
478+
479+
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 4>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 4>>, ["a"]
480+
481+
// LLVM: %[[ARR:.*]] = alloca [4 x { i32, i32 }], i64 1, align 16
482+
483+
// OGCG: %[[ARR:.*]] = alloca [4 x { i32, i32 }], align 16
484+
485+
void func12() {
486+
struct Point {
487+
int x;
488+
int y;
489+
};
490+
491+
Point a[4];
492+
}
493+
494+
// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 4>, !cir.ptr<!cir.array<!rec_Point x 4>>, ["a"]
495+
496+
// LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16
497+
498+
// OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16

clang/test/CIR/CodeGen/forrange.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ void for_range3() {
115115
// CIR: %[[C_ADDR:.*]] = cir.alloca !rec_C3{{.*}} ["c"]
116116
// CIR: cir.scope {
117117
// CIR: %[[RANGE_ADDR:.*]] = cir.alloca !cir.ptr<!rec_C3>{{.*}} ["__range1", init, const]
118-
// CIR: %[[BEGIN_ADDR:.*]] = cir.alloca !rec_Iterator, !cir.ptr<!rec_Iterator>{{.*}} ["__begin1"]
119-
// CIR: %[[END_ADDR:.*]] = cir.alloca !rec_Iterator, !cir.ptr<!rec_Iterator>{{.*}} ["__end1"]
118+
// CIR: %[[BEGIN_ADDR:.*]] = cir.alloca !rec_Iterator, !cir.ptr<!rec_Iterator>{{.*}} ["__begin1", init]
119+
// CIR: %[[END_ADDR:.*]] = cir.alloca !rec_Iterator, !cir.ptr<!rec_Iterator>{{.*}} ["__end1", init]
120120
// CIR: %[[E_ADDR:.*]] = cir.alloca !cir.ptr<!rec_Element>{{.*}} ["e", init, const]
121121
// CIR: cir.store{{.*}} %[[C_ADDR]], %[[RANGE_ADDR]]
122122
// CIR: cir.for : cond {

clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,97 @@ TEST(MinimizeSourceToDependencyDirectivesTest,
789789
Out.data());
790790
}
791791

792+
TEST(MinimizeSourceToDependencyDirectivesTest,
793+
WhitespaceAfterLineContinuationSlashLineComment) {
794+
SmallVector<char, 128> Out;
795+
796+
ASSERT_FALSE(minimizeSourceToDependencyDirectives("// some comment \\ \n"
797+
"module A;\n",
798+
Out));
799+
EXPECT_STREQ("", Out.data());
800+
}
801+
802+
TEST(MinimizeSourceToDependencyDirectivesTest,
803+
WhitespaceAfterLineContinuationSlashAllDirectives) {
804+
SmallVector<char, 512> Out;
805+
SmallVector<dependency_directives_scan::Token, 16> Tokens;
806+
SmallVector<Directive, 16> Directives;
807+
808+
StringRef Input = "#define \\ \n"
809+
"A\n"
810+
"#undef\t\\ \n"
811+
"A\n"
812+
"#endif \\\t\t\n"
813+
"\n"
814+
"#if \\ \t\n"
815+
"A\n"
816+
"#ifdef\t\\ \n"
817+
"A\n"
818+
"#ifndef \\ \t\n"
819+
"A\n"
820+
"#elifdef \\ \n"
821+
"A\n"
822+
"#elifndef \\ \n"
823+
"A\n"
824+
"#elif \\\t\t \n"
825+
"A\n"
826+
"#else \\\t \t\n"
827+
"\n"
828+
"#include \\ \n"
829+
"<A>\n"
830+
"#include_next \\ \n"
831+
"<A>\n"
832+
"#__include_macros\\ \n"
833+
"<A>\n"
834+
"#import \\ \t\n"
835+
"<A>\n"
836+
"@import \\\t \n"
837+
"A;\n"
838+
"#pragma clang \\ \n"
839+
"module \\ \n"
840+
"import A\n"
841+
"#pragma \\ \n"
842+
"push_macro(A)\n"
843+
"#pragma \\\t \n"
844+
"pop_macro(A)\n"
845+
"#pragma \\ \n"
846+
"include_alias(<A>,\\ \n"
847+
"<B>)\n"
848+
"export \\ \n"
849+
"module m;\n"
850+
"import\t\\\t \n"
851+
"m;\n"
852+
"#pragma\t\\ \n"
853+
"clang\t\\ \t\n"
854+
"system_header\n";
855+
ASSERT_FALSE(
856+
minimizeSourceToDependencyDirectives(Input, Out, Tokens, Directives));
857+
858+
EXPECT_EQ(pp_define, Directives[0].Kind);
859+
EXPECT_EQ(pp_undef, Directives[1].Kind);
860+
EXPECT_EQ(pp_endif, Directives[2].Kind);
861+
EXPECT_EQ(pp_if, Directives[3].Kind);
862+
EXPECT_EQ(pp_ifdef, Directives[4].Kind);
863+
EXPECT_EQ(pp_ifndef, Directives[5].Kind);
864+
EXPECT_EQ(pp_elifdef, Directives[6].Kind);
865+
EXPECT_EQ(pp_elifndef, Directives[7].Kind);
866+
EXPECT_EQ(pp_elif, Directives[8].Kind);
867+
EXPECT_EQ(pp_else, Directives[9].Kind);
868+
EXPECT_EQ(pp_include, Directives[10].Kind);
869+
EXPECT_EQ(pp_include_next, Directives[11].Kind);
870+
EXPECT_EQ(pp___include_macros, Directives[12].Kind);
871+
EXPECT_EQ(pp_import, Directives[13].Kind);
872+
EXPECT_EQ(decl_at_import, Directives[14].Kind);
873+
EXPECT_EQ(pp_pragma_import, Directives[15].Kind);
874+
EXPECT_EQ(pp_pragma_push_macro, Directives[16].Kind);
875+
EXPECT_EQ(pp_pragma_pop_macro, Directives[17].Kind);
876+
EXPECT_EQ(pp_pragma_include_alias, Directives[18].Kind);
877+
EXPECT_EQ(cxx_export_module_decl, Directives[19].Kind);
878+
EXPECT_EQ(cxx_import_decl, Directives[20].Kind);
879+
EXPECT_EQ(pp_pragma_system_header, Directives[21].Kind);
880+
EXPECT_EQ(pp_eof, Directives[22].Kind);
881+
}
882+
792883
TEST(MinimizeSourceToDependencyDirectivesTest, PoundWarningAndError) {
793884
SmallVector<char, 128> Out;
794885

libc/fuzzing/stdio/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_libc_fuzzer(
44
printf_parser_fuzz.cpp
55
DEPENDS
66
libc.src.stdio.printf_core.parser
7+
libc.src.errno.errno # needed for the strerror conversion
78
)
89

910
add_libc_fuzzer(

libc/include/math.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ functions:
734734
- type: float128
735735
- type: float128
736736
- type: float128
737-
guards: LIBC_TYPES_HAS_FLOAT128
737+
guard: LIBC_TYPES_HAS_FLOAT128
738738
- name: ffmal
739739
standards:
740740
- stdc

libc/include/wchar.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ functions:
109109
- stdc
110110
return_type: wchar_t *
111111
arguments:
112-
- type: __restrict wchar_t *
113-
- type: const __restrict wchar_t *
112+
- type: wchar_t *__restrict
113+
- type: const wchar_t *__restrict
114114
- type: size_t
115115
- name: wmemmove
116116
standards:
@@ -125,16 +125,16 @@ functions:
125125
- stdc
126126
return_type: wchar_t *
127127
arguments:
128-
- type: __restrict wchar_t *
129-
- type: const __restrict wchar_t *
128+
- type: wchar_t *__restrict
129+
- type: const wchar_t *__restrict
130130
- type: size_t
131131
- name: wcscat
132132
standards:
133133
- stdc
134134
return_type: wchar_t *
135135
arguments:
136-
- type: __restrict wchar_t *
137-
- type: const __restrict wchar_t *
136+
- type: wchar_t *__restrict
137+
- type: const wchar_t *__restrict
138138
- name: wcsstr
139139
standards:
140140
- stdc
@@ -147,13 +147,13 @@ functions:
147147
- stdc
148148
return_type: wchar_t *
149149
arguments:
150-
- type: __restrict wchar_t *
151-
- type: const __restrict wchar_t *
150+
- type: wchar_t *__restrict
151+
- type: const wchar_t *__restrict
152152
- type: size_t
153153
- name: wcscpy
154154
standards:
155155
- stdc
156156
return_type: wchar_t *
157157
arguments:
158-
- type: __restrict wchar_t *
159-
- type: const __restrict wchar_t *
158+
- type: wchar_t *__restrict
159+
- type: const wchar_t *__restrict

libc/src/__support/File/linux/file.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "src/__support/macros/config.h"
2020

2121
#include "hdr/fcntl_macros.h" // For mode_t and other flags to the open syscall
22-
#include <sys/stat.h> // For S_IS*, S_IF*, and S_IR* flags.
23-
#include <sys/syscall.h> // For syscall numbers
22+
#include <sys/stat.h> // For S_IS*, S_IF*, and S_IR* flags.
23+
#include <sys/syscall.h> // For syscall numbers
2424

2525
namespace LIBC_NAMESPACE_DECL {
2626

@@ -128,10 +128,11 @@ ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode) {
128128
return Error(EINVAL);
129129
}
130130

131-
int fd_flags = internal::fcntl(fd, F_GETFL);
132-
if (fd_flags == -1) {
131+
auto result = internal::fcntl(fd, F_GETFL);
132+
if (!result.has_value()) {
133133
return Error(EBADF);
134134
}
135+
int fd_flags = result.value();
135136

136137
using OpenMode = File::OpenMode;
137138
if (((fd_flags & O_ACCMODE) == O_RDONLY &&
@@ -145,8 +146,9 @@ ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode) {
145146
if ((modeflags & static_cast<ModeFlags>(OpenMode::APPEND)) &&
146147
!(fd_flags & O_APPEND)) {
147148
do_seek = true;
148-
if (internal::fcntl(fd, F_SETFL,
149-
reinterpret_cast<void *>(fd_flags | O_APPEND)) == -1) {
149+
if (!internal::fcntl(fd, F_SETFL,
150+
reinterpret_cast<void *>(fd_flags | O_APPEND))
151+
.has_value()) {
150152
return Error(EBADF);
151153
}
152154
}

0 commit comments

Comments
 (0)