Showing with 8,234 additions and 6,302 deletions.
  1. +2 −1 clang/CMakeLists.txt
  2. +52 −0 clang/include/clang/AST/Expr.h
  3. +1 −0 clang/include/clang/AST/RecursiveASTVisitor.h
  4. +3 −0 clang/include/clang/Basic/Builtins.def
  5. +6 −0 clang/include/clang/Basic/DiagnosticCommonKinds.td
  6. +7 −0 clang/include/clang/Basic/DiagnosticGroups.td
  7. +23 −1 clang/include/clang/Basic/DiagnosticLexKinds.td
  8. +5 −3 clang/include/clang/Basic/FileManager.h
  9. +1 −0 clang/include/clang/Basic/StmtNodes.td
  10. +5 −0 clang/include/clang/Basic/TokenKinds.def
  11. +16 −0 clang/include/clang/Driver/Options.td
  12. +2 −0 clang/include/clang/Frontend/PreprocessorOutputOptions.h
  13. +118 −82 clang/include/clang/Lex/PPCallbacks.h
  14. +32 −0 clang/include/clang/Lex/PPDirectiveParameter.h
  15. +78 −0 clang/include/clang/Lex/PPEmbedParameters.h
  16. +191 −128 clang/include/clang/Lex/Preprocessor.h
  17. +7 −0 clang/include/clang/Lex/PreprocessorOptions.h
  18. +1 −1 clang/include/clang/Lex/Token.h
  19. +1,124 −1,441 clang/include/clang/Sema/Sema.h
  20. +3 −0 clang/include/clang/Serialization/ASTBitCodes.h
  21. +17 −0 clang/lib/AST/Expr.cpp
  22. +4 −0 clang/lib/AST/ExprClassification.cpp
  23. +8 −0 clang/lib/AST/ExprConstant.cpp
  24. +1 −0 clang/lib/AST/ItaniumMangle.cpp
  25. +7 −0 clang/lib/AST/StmtPrinter.cpp
  26. +4 −0 clang/lib/AST/StmtProfile.cpp
  27. +41 −35 clang/lib/Basic/FileManager.cpp
  28. +2 −1 clang/lib/Basic/IdentifierTable.cpp
  29. +4 −1 clang/lib/Driver/ToolChains/Clang.cpp
  30. +2 −0 clang/lib/Format/FormatToken.h
  31. +28 −0 clang/lib/Format/TokenAnnotator.cpp
  32. +21 −0 clang/lib/Frontend/CompilerInvocation.cpp
  33. +29 −0 clang/lib/Frontend/DependencyFile.cpp
  34. +51 −15 clang/lib/Frontend/DependencyGraph.cpp
  35. +7 −0 clang/lib/Frontend/InitPreprocessor.cpp
  36. +50 −32 clang/lib/Frontend/PrintPreprocessedOutput.cpp
  37. +98 −85 clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  38. +1 −0 clang/lib/Interpreter/Interpreter.cpp
  39. +8 −0 clang/lib/Lex/Lexer.cpp
  40. +0 −11 clang/lib/Lex/PPCallbacks.cpp
  41. +942 −174 clang/lib/Lex/PPDirectives.cpp
  42. +137 −88 clang/lib/Lex/PPExpressions.cpp
  43. +124 −0 clang/lib/Lex/PPMacroExpansion.cpp
  44. +3 −2 clang/lib/Lex/Preprocessor.cpp
  45. +0 −1 clang/lib/Parse/ParseDeclCXX.cpp
  46. +361 −308 clang/lib/Parse/ParseExpr.cpp
  47. +3 −3 clang/lib/Parse/ParseInit.cpp
  48. +2 −0 clang/lib/Parse/ParseTemplate.cpp
  49. +1,389 −1,383 clang/lib/Sema/SemaDecl.cpp
  50. +2 −1 clang/lib/Sema/SemaDeclCXX.cpp
  51. +1 −0 clang/lib/Sema/SemaExceptionSpec.cpp
  52. +1,799 −1,483 clang/lib/Sema/SemaExpr.cpp
  53. +947 −1,002 clang/lib/Sema/SemaTemplate.cpp
  54. +2 −2 clang/lib/Sema/SemaTemplateVariadic.cpp
  55. +7 −0 clang/lib/Sema/TreeTransform.h
  56. +13 −0 clang/lib/Serialization/ASTReaderStmt.cpp
  57. +10 −0 clang/lib/Serialization/ASTWriterStmt.cpp
  58. +4 −0 clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  59. +1 −0 clang/test/Preprocessor/Inputs/jk.txt
  60. +9 −0 clang/test/Preprocessor/Inputs/media/art.txt
  61. 0 clang/test/Preprocessor/Inputs/media/empty
  62. +1 −0 clang/test/Preprocessor/Inputs/single_byte.txt
  63. +34 −0 clang/test/Preprocessor/embed___has_embed.c
  64. +24 −0 clang/test/Preprocessor/embed___has_embed_supported.c
  65. +106 −0 clang/test/Preprocessor/embed_art.c
  66. +13 −0 clang/test/Preprocessor/embed_feature_test.cpp
  67. +4 −0 clang/test/Preprocessor/embed_file_not_found.c
  68. +28 −0 clang/test/Preprocessor/embed_init.c
  69. +16 −0 clang/test/Preprocessor/embed_parameter_if_empty.c
  70. +15 −0 clang/test/Preprocessor/embed_parameter_limit.c
  71. +15 −0 clang/test/Preprocessor/embed_parameter_offset.c
  72. +15 −0 clang/test/Preprocessor/embed_parameter_prefix.c
  73. +15 −0 clang/test/Preprocessor/embed_parameter_suffix.c
  74. +8 −0 clang/test/Preprocessor/embed_parameter_unrecognized.c
  75. +8 −0 clang/test/Preprocessor/embed_path_chevron.c
  76. +8 −0 clang/test/Preprocessor/embed_path_quote.c
  77. +7 −0 clang/test/Preprocessor/embed_single_entity.c
  78. +68 −0 clang/test/Preprocessor/embed_weird.cpp
  79. +1 −0 clang/test/Preprocessor/single_byte.txt
  80. +8 −0 llvm/CMakeLists.txt
  81. +3 −3 llvm/cmake/modules/GetHostTriple.cmake
  82. +21 −15 llvm/include/llvm/Support/Base64.h
3 changes: 2 additions & 1 deletion clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,15 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/include/clang/Basic/Version.inc)

# Add appropriate flags for GCC
option(CLANG_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-common -Woverloaded-virtual")
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
endif ()

# Enable -pedantic for Clang even if it's not enabled for LLVM.
if (NOT LLVM_ENABLE_PEDANTIC)
if (NOT LLVM_ENABLE_PEDANTIC AND CLANG_ENABLE_PEDANTIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wno-long-long")
endif ()

Expand Down
52 changes: 52 additions & 0 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4805,6 +4805,58 @@ class SourceLocExpr final : public Expr {
friend class ASTStmtReader;
};

/// Represents a function call to __builtin_pp_embed().
class PPEmbedExpr final : public Expr {
SourceLocation BuiltinLoc, RParenLoc;
DeclContext *ParentContext;
StringLiteral *Filename;
StringLiteral *BinaryData;

public:
enum Action {
NotFound,
FoundOne,
Expanded,
};

PPEmbedExpr(const ASTContext &Ctx, QualType ResultTy, StringLiteral* Filename, StringLiteral* BinaryData,
SourceLocation BLoc, SourceLocation RParenLoc,
DeclContext *Context);

/// Build an empty call expression.
explicit PPEmbedExpr(EmptyShell Empty)
: Expr(SourceLocExprClass, Empty) {}

/// If the PPEmbedExpr has been resolved return the subexpression
/// representing the resolved value. Otherwise return null.
const DeclContext *getParentContext() const { return ParentContext; }
DeclContext *getParentContext() { return ParentContext; }

SourceLocation getLocation() const { return BuiltinLoc; }
SourceLocation getBeginLoc() const { return BuiltinLoc; }
SourceLocation getEndLoc() const { return RParenLoc; }

StringLiteral *getFilenameStringLiteral() const { return Filename; }
StringLiteral *getDataStringLiteral() const { return BinaryData; }

size_t getDataElementCount(ASTContext &Context) const;

child_range children() {
return child_range(child_iterator(), child_iterator());
}

const_child_range children() const {
return const_child_range(child_iterator(), child_iterator());
}

static bool classof(const Stmt *T) {
return T->getStmtClass() == PPEmbedExprClass;
}

private:
friend class ASTStmtReader;
};

/// Describes an C or C++ initializer list.
///
/// InitListExpr describes an initializer list, which can be used to
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,7 @@ DEF_TRAVERSE_STMT(ShuffleVectorExpr, {})
DEF_TRAVERSE_STMT(ConvertVectorExpr, {})
DEF_TRAVERSE_STMT(StmtExpr, {})
DEF_TRAVERSE_STMT(SourceLocExpr, {})
DEF_TRAVERSE_STMT(PPEmbedExpr, {})

DEF_TRAVERSE_STMT(UnresolvedLookupExpr, {
TRY_TO(TraverseNestedNameSpecifierLoc(S->getQualifierLoc()));
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,9 @@ BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
// Arithmetic Fence: to prevent FP reordering and reassociation optimizations
LANGBUILTIN(__arithmetic_fence, "v.", "tE", ALL_LANGUAGES)

// preprocessor embed builtin
LANGBUILTIN(__builtin_pp_embed, "v.", "tE", ALL_LANGUAGES)

#undef BUILTIN
#undef LIBBUILTIN
#undef LANGBUILTIN
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/DiagnosticCommonKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def err_expected_string_literal : Error<"expected string literal "
"'external_source_symbol' attribute|"
"as argument of '%1' attribute}0">;

def err_builtin_pp_embed_invalid_argument : Error<
"invalid argument to '__builtin_pp_embed': %0">;

def err_invalid_string_udl : Error<
"string literal with user-defined suffix cannot be used here">;
def err_invalid_character_udl : Error<
Expand All @@ -80,6 +83,9 @@ def err_expected : Error<"expected %0">;
def err_expected_either : Error<"expected %0 or %1">;
def err_expected_after : Error<"expected %1 after %0">;

def err_builtin_pp_embed_invalid_location : Error<
"'__builtin_pp_embed' in invalid location: %0%select{|%2}1">;

def err_param_redefinition : Error<"redefinition of parameter %0">;
def warn_method_param_redefinition : Warning<"redefinition of method parameter %0">;
def warn_method_param_declaration : Warning<"redeclaration of method parameter %0">,
Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,20 @@ def ReservedIdAsMacro : DiagGroup<"reserved-macro-identifier">;
def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", [ReservedIdAsMacro]>;
def RestrictExpansionMacro : DiagGroup<"restrict-expansion">;
def FinalMacro : DiagGroup<"final-macro">;
// Warnings about unknown preprocessor parameters (e.g. `#embed` and extensions)
def UnsupportedDirective : DiagGroup<"unsupported-directive">;
def UnknownDirectiveParameters : DiagGroup<"unknown-directive-parameters">;
def IgnoredDirectiveParameters : DiagGroup<"ignored-directive-parameters">;
def DirectiveParameters : DiagGroup<"directive-parameters",
[UnknownDirectiveParameters, IgnoredDirectiveParameters]>;

// Just silence warnings about -Wstrict-aliasing for now.
def : DiagGroup<"strict-aliasing=0">;
def : DiagGroup<"strict-aliasing=1">;
def : DiagGroup<"strict-aliasing=2">;
def : DiagGroup<"strict-aliasing">;


// Just silence warnings about -Wstrict-overflow for now.
def : DiagGroup<"strict-overflow=0">;
def : DiagGroup<"strict-overflow=1">;
Expand Down
24 changes: 23 additions & 1 deletion clang/include/clang/Basic/DiagnosticLexKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@ def warn_cxx23_compat_warning_directive : Warning<
def warn_c23_compat_warning_directive : Warning<
"#warning is incompatible with C standards before C23">,
InGroup<CPre23Compat>, DefaultIgnore;
def warn_c23_pp_embed : Warning<
"'__has_embed' is a C23 extension">,
InGroup<CPre23Compat>,
DefaultIgnore;
def warn_c23_pp_has_embed : Warning<
"'__has_embed' is a C23 extension">,
InGroup<CPre23Compat>,
DefaultIgnore;
def warn_cxx26_pp_embed : Warning<
"'__has_embed' is a C++26 extension">,
InGroup<CXXPre26Compat>,
DefaultIgnore;
def warn_cxx26_pp_has_embed : Warning<
"'__has_embed' is a C++26 extension">,
InGroup<CXXPre26Compat>,
DefaultIgnore;

def ext_pp_extra_tokens_at_eol : ExtWarn<
"extra tokens at end of #%0 directive">, InGroup<ExtraTokens>;
Expand Down Expand Up @@ -483,7 +499,13 @@ def ext_pp_gnu_line_directive : Extension<
def err_pp_invalid_directive : Error<
"invalid preprocessing directive%select{|, did you mean '#%1'?}0">;
def warn_pp_invalid_directive : Warning<
err_pp_invalid_directive.Summary>, InGroup<DiagGroup<"unknown-directives">>;
err_pp_invalid_directive.Summary>,
InGroup<UnsupportedDirective>;
def warn_pp_unknown_parameter_ignored : Warning<
"unknown%select{ | embed}0 preprocessor parameter '%1' ignored">,
InGroup<UnknownDirectiveParameters>;
def err_pp_unsupported_directive : Error<
"unsupported%select{ | embed}0 directive: %1">;
def err_pp_directive_required : Error<
"%0 must be used within a preprocessing directive">;
def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
Expand Down
8 changes: 5 additions & 3 deletions clang/include/clang/Basic/FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ class FileManager : public RefCountedBase<FileManager> {
/// MemoryBuffer if successful, otherwise returning null.
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getBufferForFile(FileEntryRef Entry, bool isVolatile = false,
bool RequiresNullTerminator = true);
bool RequiresNullTerminator = true,
std::optional<int64_t> MaybeLimit = std::nullopt);
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
getBufferForFile(StringRef Filename, bool isVolatile = false,
bool RequiresNullTerminator = true) {
return getBufferForFileImpl(Filename, /*FileSize=*/-1, isVolatile,
bool RequiresNullTerminator = true,
std::optional<int64_t> MaybeLimit = std::nullopt) {
return getBufferForFileImpl(Filename, /*FileSize=*/(MaybeLimit ? *MaybeLimit : -1), isVolatile,
RequiresNullTerminator);
}

Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/StmtNodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def OpaqueValueExpr : StmtNode<Expr>;
def TypoExpr : StmtNode<Expr>;
def RecoveryExpr : StmtNode<Expr>;
def BuiltinBitCastExpr : StmtNode<ExplicitCastExpr>;
def PPEmbedExpr : StmtNode<Expr>;

// Microsoft Extensions.
def MSPropertyRefExpr : StmtNode<Expr>;
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/Basic/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ PPKEYWORD(error)
// C99 6.10.6 - Pragma Directive.
PPKEYWORD(pragma)

// C23 & C++26 #embed
PPKEYWORD(embed)

// GNU Extensions.
PPKEYWORD(import)
PPKEYWORD(include_next)
Expand Down Expand Up @@ -751,6 +754,7 @@ ALIAS("__char32_t" , char32_t , KEYCXX)
KEYWORD(__builtin_bit_cast , KEYALL)
KEYWORD(__builtin_available , KEYALL)
KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL)
KEYWORD(__builtin_pp_embed , KEYALL)

// Keywords defined by Attr.td.
#ifndef KEYWORD_ATTRIBUTE
Expand Down Expand Up @@ -986,6 +990,7 @@ ANNOTATION(repl_input_end)
#undef CXX11_KEYWORD
#undef KEYWORD
#undef PUNCTUATOR
#undef BUILTINOK
#undef TOK
#undef C99_KEYWORD
#undef C23_KEYWORD
Expand Down
16 changes: 16 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def IncludePath_Group : OptionGroup<"<I/i group>">, Group<Preprocessor_Group>,
DocBrief<[{
Flags controlling how ``#include``\s are resolved to files.}]>;

def EmbedPath_Group : OptionGroup<"<Embed group>">, Group<Preprocessor_Group>,
DocName<"Embed path management">,
DocBrief<[{
Flags controlling how ``#embed``\s and similar are resolved to files.}]>;

def I_Group : OptionGroup<"<I group>">, Group<IncludePath_Group>, DocFlatten;
def i_Group : OptionGroup<"<i group>">, Group<IncludePath_Group>, DocFlatten;
def clang_i_Group : OptionGroup<"<clang i group>">, Group<i_Group>, DocFlatten;
Expand Down Expand Up @@ -816,6 +821,14 @@ will be ignored}]>;
def L : JoinedOrSeparate<["-"], "L">, Flags<[RenderJoined]>, Group<Link_Group>,
Visibility<[ClangOption, FlangOption]>,
MetaVarName<"<dir>">, HelpText<"Add directory to library search path">;
def embed_dir : JoinedOrSeparate<["-"], "embed-dir">,
Flags<[RenderJoined]>, Group<EmbedPath_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption, FlangOption, FC1Option]>,
MetaVarName<"<dir>">, HelpText<"Add directory to embed search path">;
def embed_dir_EQ : JoinedOrSeparate<["-"], "embed-dir=">,
Flags<[RenderJoined]>, Group<EmbedPath_Group>,
Visibility<[ClangOption, CC1Option, CC1AsOption, FlangOption, FC1Option]>,
MetaVarName<"<dir>">, HelpText<"Add directory to embed search path">;
def MD : Flag<["-"], "MD">, Group<M_Group>,
HelpText<"Write a depfile containing user and system headers">;
def MMD : Flag<["-"], "MMD">, Group<M_Group>,
Expand Down Expand Up @@ -1353,6 +1366,9 @@ def dD : Flag<["-"], "dD">, Group<d_Group>, Visibility<[ClangOption, CC1Option]>
def dI : Flag<["-"], "dI">, Group<d_Group>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Print include directives in -E mode in addition to normal output">,
MarshallingInfoFlag<PreprocessorOutputOpts<"ShowIncludeDirectives">>;
def dE : Flag<["-"], "dE">, Group<d_Group>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Print embed directives in -E mode in addition to normal output">,
MarshallingInfoFlag<PreprocessorOutputOpts<"ShowEmbedDirectives">>;
def dM : Flag<["-"], "dM">, Group<d_Group>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Print macro definitions in -E mode instead of normal output">;
def dead__strip : Flag<["-"], "dead_strip">;
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Frontend/PreprocessorOutputOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PreprocessorOutputOptions {
unsigned ShowMacroComments : 1; ///< Show comments, even in macros.
unsigned ShowMacros : 1; ///< Print macro definitions.
unsigned ShowIncludeDirectives : 1; ///< Print includes, imports etc. within preprocessed output.
unsigned ShowEmbedDirectives : 1; ///< Print embeds, etc. within preprocessed output.
unsigned RewriteIncludes : 1; ///< Preprocess include directives only.
unsigned RewriteImports : 1; ///< Include contents of transitively-imported modules.
unsigned MinimizeWhitespace : 1; ///< Ignore whitespace from input.
Expand All @@ -37,6 +38,7 @@ class PreprocessorOutputOptions {
ShowMacroComments = 0;
ShowMacros = 0;
ShowIncludeDirectives = 0;
ShowEmbedDirectives = 0;
RewriteIncludes = 0;
RewriteImports = 0;
MinimizeWhitespace = 0;
Expand Down
Loading