Skip to content

Commit 199ddbd

Browse files
apply suggestions
1 parent 830f4e9 commit 199ddbd

File tree

6 files changed

+66
-64
lines changed

6 files changed

+66
-64
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ Non-comprehensive list of changes in this release
327327
``__reference_constructs_from_temporary`` should be used instead. (#GH44056)
328328
- Added `__builtin_get_vtable_pointer` to directly load the primary vtable pointer from a
329329
polymorphic object.
330+
- `libclang` receives a family of new bindings to query basic facts about
331+
GCC-style inline assembly blocks, including whether the block is `volatile`
332+
and its template string following the LLVM IR `asm` format. (#GH143424)
330333
- Clang no longer rejects reinterpret_cast conversions between indirect
331334
ARC-managed pointers and other pointer types. The prior behavior was overly
332335
strict and inconsistent with the ARC specification.

clang/include/clang-c/Index.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,32 +4518,46 @@ CINDEX_LINKAGE CXStringSet *clang_Cursor_getObjCManglings(CXCursor);
45184518
* The index N in both cases points into the the total inputs and outputs,
45194519
* or more specifically, into the list of outputs followed by the inputs,
45204520
* starting from index 0 as the first available template argument.
4521+
*
4522+
* This function also returns a valid empty string if the cursor does not point
4523+
* at a GCC inline assembly block.
45214524
*/
45224525

45234526
CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor);
45244527

45254528
/**
45264529
* Given a CXCursor_GCCAsmStmt cursor, check if the assembly block has goto
45274530
* labels.
4531+
* This function also returns FALSE if the cursor does not point at a GCC inline
4532+
* assembly block.
45284533
*/
45294534

45304535
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor);
45314536

45324537
/**
4533-
* Given a CXCursor_GCCAsmStmt cursor, count the number of outputs
4538+
* Given a CXCursor_GCCAsmStmt cursor, count the number of outputs.
4539+
* This function also returns 0 if the cursor does not point at a GCC inline
4540+
* assembly block.
45344541
*/
45354542

45364543
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor);
45374544

45384545
/**
4539-
* Given a CXCursor_GCCAsmStmt cursor, count the number of inputs
4546+
* Given a CXCursor_GCCAsmStmt cursor, count the number of inputs.
4547+
* This function also returns 0 if the cursor does not point at a GCC inline
4548+
* assembly block.
45404549
*/
45414550

45424551
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor);
45434552

45444553
/**
45454554
* Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
45464555
* to the Index-th input.
4556+
* This function returns TRUE when the cursor points at a GCC inline assembly
4557+
* statement, `Index` is within bounds and both the `Constraint` and `Expr` are
4558+
* not NULL.
4559+
* Otherwise, this function returns FALSE but leaves `Constraint` and `Expr`
4560+
* intact.
45474561
*/
45484562

45494563
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
@@ -4554,6 +4568,11 @@ CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor,
45544568
/**
45554569
* Given a CXCursor_GCCAsmStmt cursor, get the constraint and expression cursor
45564570
* to the Index-th output.
4571+
* This function returns TRUE when the cursor points at a GCC inline assembly
4572+
* statement, `Index` is within bounds and both the `Constraint` and `Expr` are
4573+
* not NULL.
4574+
* Otherwise, this function returns FALSE but leaves `Constraint` and `Expr`
4575+
* intact.
45574576
*/
45584577

45594578
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
@@ -4563,26 +4582,26 @@ CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor,
45634582

45644583
/**
45654584
* Given a CXCursor_GCCAsmStmt cursor, count the clobbers in it.
4585+
* This function also returns 0 if the cursor does not point at a GCC inline
4586+
* assembly block.
45664587
*/
45674588

45684589
CINDEX_LINKAGE unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor);
45694590

45704591
/**
45714592
* Given a CXCursor_GCCAsmStmt cursor, get the Index-th clobber of it.
4593+
* This function returns a valid empty string if the cursor does not point
4594+
* at a GCC inline assembly block or `Index` is out of bounds.
45724595
*/
45734596

45744597
CINDEX_LINKAGE CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor,
45754598
unsigned Index);
45764599

4577-
/**
4578-
* Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is simple.
4579-
*/
4580-
4581-
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblySimple(CXCursor Cursor);
4582-
45834600
/**
45844601
* Given a CXCursor_GCCAsmStmt cursor, check if the inline assembly is
45854602
* `volatile`.
4603+
* This function returns FALSE if the cursor does not point at a GCC inline
4604+
* assembly block.
45864605
*/
45874606

45884607
CINDEX_LINKAGE unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor);

clang/test/Index/inline-assembly.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ static void inline_assembly_template_regardless_of_target_machine() {
1717
// CHECK: o_value ${1:w}
1818
// CHECK: ===ASM TEMPLATE END===
1919
// CHECK: volatile: true
20-
// CHECK: simple: false
2120
// CHECK: Output #0 Constraint (=&r): DeclRefExpr=tmp:2:9
2221
// CHECK: Input #0 Constraint (r): UnexposedExpr=tmp:2:9
2322
// CHECK: Clobber #0: cc
@@ -40,9 +39,8 @@ static void inline_assembly_valid_x86_example() {
4039
// CHECK: mov ${1:w}, ${0:w}
4140
// CHECK: ===ASM TEMPLATE END===
4241
// CHECK: volatile: false
43-
// CHECK: simple: false
44-
// CHECK: Output #0 Constraint (=&r): DeclRefExpr=tmp:28:9
45-
// CHECK: Input #0 Constraint (r): UnexposedExpr=tmp:28:9
42+
// CHECK: Output #0 Constraint (=&r): DeclRefExpr=tmp:27:9
43+
// CHECK: Input #0 Constraint (r): UnexposedExpr=tmp:27:9
4644
// CHECK: Clobber #0: cc
4745
// CHECK: Clobber #1: memory
4846
// CHECK: ===ASM END===

clang/tools/c-index-test/c-index-test.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,9 +1997,9 @@ PrintGCCInlineAssembly(CXCursor cursor, CXCursor p, CXClientData d) {
19971997
CXString Constraint, Template, Clobber;
19981998
CXCursor Expr;
19991999
unsigned hasGoto, i, e;
2000-
if (clang_getCursorKind(cursor) != CXCursor_AsmStmt) {
2000+
if (clang_getCursorKind(cursor) != CXCursor_AsmStmt)
20012001
return CXChildVisit_Recurse;
2002-
}
2002+
20032003
hasGoto = clang_Cursor_isGCCAssemblyHasGoto(cursor);
20042004
printf("===ASM TEMPLATE%s===\n", hasGoto ? " (WITH GOTO)" : "");
20052005
Template = clang_Cursor_getGCCAssemblyTemplate(cursor);
@@ -2009,8 +2009,6 @@ PrintGCCInlineAssembly(CXCursor cursor, CXCursor p, CXClientData d) {
20092009

20102010
printf("volatile: %s\n",
20112011
clang_Cursor_isGCCAssemblyVolatile(cursor) ? "true" : "false");
2012-
printf("simple: %s\n",
2013-
clang_Cursor_isGCCAssemblySimple(cursor) ? "true" : "false");
20142012

20152013
for (i = 0, e = clang_Cursor_getGCCAssemblyNumOutputs(cursor); i < e; ++i) {
20162014
clang_Cursor_getGCCAssemblyOutput(cursor, i, &Constraint, &Expr);

clang/tools/libclang/CIndex.cpp

Lines changed: 32 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8653,9 +8653,9 @@ void clang_annotateTokens(CXTranslationUnit TU, CXToken *Tokens,
86538653
CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor Cursor) {
86548654
if (!clang_isStatement(Cursor.kind))
86558655
return cxstring::createEmpty();
8656-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8657-
auto const &C = getCursorContext(Cursor);
8658-
auto AsmTemplate = Stmt->generateAsmString(C);
8656+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8657+
ASTContext const &C = getCursorContext(Cursor);
8658+
std::string AsmTemplate = S->generateAsmString(C);
86598659
return cxstring::createDup(AsmTemplate);
86608660
}
86618661
return cxstring::createEmpty();
@@ -8664,59 +8664,56 @@ CXString clang_Cursor_getGCCAssemblyTemplate(CXCursor Cursor) {
86648664
unsigned clang_Cursor_isGCCAssemblyHasGoto(CXCursor Cursor) {
86658665
if (!clang_isStatement(Cursor.kind))
86668666
return 0;
8667-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8668-
return Stmt->isAsmGoto();
8669-
}
8667+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8668+
return S->isAsmGoto();
86708669
return 0;
86718670
}
86728671

86738672
unsigned clang_Cursor_getGCCAssemblyNumOutputs(CXCursor Cursor) {
86748673
if (!clang_isStatement(Cursor.kind))
86758674
return 0;
8676-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8677-
return Stmt->getNumOutputs();
8678-
}
8675+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8676+
return S->getNumOutputs();
86798677
return 0;
86808678
}
86818679

86828680
unsigned clang_Cursor_getGCCAssemblyNumInputs(CXCursor Cursor) {
86838681
if (!clang_isStatement(Cursor.kind))
86848682
return 0;
8685-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8686-
return Stmt->getNumInputs();
8687-
}
8683+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8684+
return S->getNumInputs();
86888685
return 0;
86898686
}
86908687

86918688
unsigned clang_Cursor_getGCCAssemblyInput(CXCursor Cursor, unsigned Index,
86928689
CXString *Constraint,
8693-
CXCursor *Expr) {
8694-
if (!clang_isStatement(Cursor.kind) || !Constraint || !Expr)
8690+
CXCursor *ExprCursor) {
8691+
if (!clang_isStatement(Cursor.kind) || !Constraint || !ExprCursor)
86958692
return 0;
8696-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8697-
Stmt && Index < Stmt->getNumInputs()) {
8698-
auto Constraint_ = Stmt->getInputConstraint(Index);
8699-
auto const *Expr_ = Stmt->getInputExpr(Index);
8693+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8694+
S && Index < S->getNumInputs()) {
8695+
std::string Constraint_ = S->getInputConstraint(Index);
8696+
Expr const *E = S->getInputExpr(Index);
87008697
*Constraint = cxstring::createDup(Constraint_);
8701-
*Expr = MakeCXCursor(Expr_, getCursorDecl(Cursor),
8702-
cxcursor::getCursorTU(Cursor));
8698+
*ExprCursor =
8699+
MakeCXCursor(E, getCursorDecl(Cursor), cxcursor::getCursorTU(Cursor));
87038700
return 1;
87048701
}
87058702
return 0;
87068703
}
87078704

87088705
unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor, unsigned Index,
87098706
CXString *Constraint,
8710-
CXCursor *Expr) {
8711-
if (!clang_isStatement(Cursor.kind) || !Constraint || !Expr)
8707+
CXCursor *ExprCursor) {
8708+
if (!clang_isStatement(Cursor.kind) || !Constraint || !ExprCursor)
87128709
return 0;
8713-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8714-
Stmt && Index < Stmt->getNumOutputs()) {
8715-
auto Constraint_ = Stmt->getOutputConstraint(Index);
8716-
auto const *Expr_ = Stmt->getOutputExpr(Index);
8710+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8711+
S && Index < S->getNumOutputs()) {
8712+
std::string Constraint_ = S->getOutputConstraint(Index);
8713+
Expr const *E = S->getOutputExpr(Index);
87178714
*Constraint = cxstring::createDup(Constraint_);
8718-
*Expr = MakeCXCursor(Expr_, getCursorDecl(Cursor),
8719-
cxcursor::getCursorTU(Cursor));
8715+
*ExprCursor =
8716+
MakeCXCursor(E, getCursorDecl(Cursor), cxcursor::getCursorTU(Cursor));
87208717
return 1;
87218718
}
87228719
return 0;
@@ -8725,37 +8722,25 @@ unsigned clang_Cursor_getGCCAssemblyOutput(CXCursor Cursor, unsigned Index,
87258722
unsigned clang_Cursor_getGCCAssemblyNumClobbers(CXCursor Cursor) {
87268723
if (!clang_isStatement(Cursor.kind))
87278724
return 0;
8728-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8729-
return Stmt->getNumClobbers();
8730-
}
8725+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8726+
return S->getNumClobbers();
87318727
return 0;
87328728
}
87338729

87348730
CXString clang_Cursor_getGCCAssemblyClobber(CXCursor Cursor, unsigned Index) {
87358731
if (!clang_isStatement(Cursor.kind))
87368732
return cxstring::createEmpty();
8737-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8738-
Stmt && Stmt->getNumClobbers()) {
8739-
return cxstring::createDup(Stmt->getClobber(Index));
8740-
}
8733+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor));
8734+
S && S->getNumClobbers())
8735+
return cxstring::createDup(S->getClobber(Index));
87418736
return cxstring::createEmpty();
87428737
}
87438738

8744-
unsigned clang_Cursor_isGCCAssemblySimple(CXCursor Cursor) {
8745-
if (!clang_isStatement(Cursor.kind))
8746-
return 0;
8747-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8748-
return Stmt->isSimple();
8749-
}
8750-
return 0;
8751-
}
8752-
87538739
unsigned clang_Cursor_isGCCAssemblyVolatile(CXCursor Cursor) {
87548740
if (!clang_isStatement(Cursor.kind))
87558741
return 0;
8756-
if (auto const *Stmt = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor))) {
8757-
return Stmt->isVolatile();
8758-
}
8742+
if (auto const *S = dyn_cast_or_null<GCCAsmStmt>(getCursorStmt(Cursor)))
8743+
return S->isVolatile();
87598744
return 0;
87608745
}
87618746

clang/tools/libclang/libclang.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ LLVM_21 {
449449
clang_Cursor_getGCCAssemblyOutput;
450450
clang_Cursor_getGCCAssemblyNumClobbers;
451451
clang_Cursor_getGCCAssemblyClobber;
452-
clang_Cursor_isGCCAssemblySimple;
453452
clang_Cursor_isGCCAssemblyVolatile;
454453
};
455454

0 commit comments

Comments
 (0)